aria.c revision 1.22 1 /* $NetBSD: aria.c,v 1.22 2005/01/10 22:01:37 kent Exp $ */
2
3 /*-
4 * Copyright (c) 1995, 1996, 1998 Roland C. Dowdeswell. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Roland C. Dowdeswell.
17 * 4. The name of the authors may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*-
33 * TODO:
34 * o Test the driver on cards other than a single
35 * Prometheus Aria 16.
36 * o Look into where aria_prometheus_kludge() belongs.
37 * o Add some DMA code. It accomplishes its goal by
38 * direct IO at the moment.
39 * o Different programs should be able to open the device
40 * with O_RDONLY and O_WRONLY at the same time. But I
41 * do not see support for this in /sys/dev/audio.c, so
42 * I cannot effectively code it.
43 * o We should nicely deal with the cards that can do mu-law
44 * and A-law output.
45 * o Rework the mixer interface.
46 * o Deal with the lvls better. We need to do better mapping
47 * between logarithmic scales and the one byte that
48 * we are passed.
49 * o Deal better with cards that have no mixer.
50 */
51
52 #include <sys/cdefs.h>
53 __KERNEL_RCSID(0, "$NetBSD: aria.c,v 1.22 2005/01/10 22:01:37 kent Exp $");
54
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/errno.h>
58 #include <sys/ioctl.h>
59 #include <sys/syslog.h>
60 #include <sys/device.h>
61 #include <sys/proc.h>
62 #include <sys/buf.h>
63 #include <sys/fcntl.h>
64
65 #include <machine/cpu.h>
66 #include <machine/bus.h>
67
68 #include <sys/audioio.h>
69 #include <dev/audio_if.h>
70 #include <dev/auconv.h>
71
72 #include <dev/mulaw.h>
73 #include <dev/isa/isavar.h>
74
75 #include <dev/isa/ariareg.h>
76
77 #ifdef AUDIO_DEBUG
78 #define DPRINTF(x) printf x
79 int ariadebug = 0;
80 #else
81 #define DPRINTF(x)
82 #endif
83
84 struct aria_mixdev_info {
85 u_char num_channels;
86 u_char level[2];
87 u_char mute;
88 };
89
90 struct aria_mixmaster {
91 u_char num_channels;
92 u_char level[2];
93 u_char treble[2];
94 u_char bass[2];
95 };
96
97 struct aria_softc {
98 struct device sc_dev; /* base device */
99 void *sc_ih; /* interrupt vectoring */
100 bus_space_tag_t sc_iot; /* Tag on 'da bus. */
101 bus_space_handle_t sc_ioh; /* Handle of iospace */
102 isa_chipset_tag_t sc_ic; /* ISA chipset info */
103
104 u_short sc_open; /* reference count of open calls */
105 u_short sc_play; /* non-paused play chans 2**chan */
106 u_short sc_record; /* non-paused record chans 2**chan */
107 /* XXX -- keep this? */
108 u_short sc_gain[2]; /* left/right gain (play) */
109
110 u_long sc_rate; /* Sample rate for input and output */
111 u_int sc_encoding; /* audio encoding -- mu-law/linear */
112 int sc_chans; /* # of channels */
113 int sc_precision; /* # bits per sample */
114
115 u_long sc_interrupts; /* number of interrupts taken */
116 void (*sc_rintr)(void*); /* record transfer completion intr handler */
117 void (*sc_pintr)(void*); /* play transfer completion intr handler */
118 void *sc_rarg; /* arg for sc_rintr() */
119 void *sc_parg; /* arg for sc_pintr() */
120
121 int sc_blocksize; /* literal dio block size */
122 void *sc_rdiobuffer; /* record: where the next samples should be */
123 void *sc_pdiobuffer; /* play: where the next samples are */
124
125 u_short sc_hardware; /* bit field of hardware present */
126 #define ARIA_TELEPHONE 0x0001 /* has telephone input */
127 #define ARIA_MIXER 0x0002 /* has SC18075 digital mixer */
128 #define ARIA_MODEL 0x0004 /* is SC18025 (=0) or SC18026 (=1) */
129
130 struct aria_mixdev_info aria_mix[6];
131 struct aria_mixmaster ariamix_master;
132 u_char aria_mix_source;
133
134 int sc_sendcmd_err;
135 };
136
137 int ariaprobe __P((struct device *, struct cfdata *, void *));
138 void ariaattach __P((struct device *, struct device *, void *));
139 void ariaclose __P((void *));
140 int ariaopen __P((void *, int));
141 int ariareset __P((bus_space_tag_t, bus_space_handle_t));
142 int aria_reset __P((struct aria_softc *));
143 int aria_getdev __P((void *, struct audio_device *));
144
145 void aria_do_kludge __P((bus_space_tag_t, bus_space_handle_t,
146 bus_space_handle_t,
147 u_short, u_short, u_short, u_short));
148 void aria_prometheus_kludge __P((struct isa_attach_args *,
149 bus_space_handle_t));
150
151 int aria_query_encoding __P((void *, struct audio_encoding *));
152 int aria_round_blocksize __P((void *, int, int, const audio_params_t *));
153 int aria_speaker_ctl __P((void *, int));
154 int aria_commit_settings __P((void *));
155 int aria_set_params __P((void *, int, int, audio_params_t *,
156 audio_params_t *, stream_filter_list_t *,
157 stream_filter_list_t *));
158 int aria_get_props __P((void *));
159
160 int aria_start_output __P((void *, void *, int,
161 void (*) __P((void *)), void*));
162 int aria_start_input __P((void *, void *, int,
163 void (*) __P((void *)), void*));
164
165 int aria_halt_input __P((void *));
166 int aria_halt_output __P((void *));
167
168 int aria_sendcmd __P((struct aria_softc *, u_short, int, int, int));
169
170 u_short aria_getdspmem __P((struct aria_softc *, u_short));
171 void aria_putdspmem __P((struct aria_softc *, u_short, u_short));
172
173 int aria_intr __P((void *));
174 short ariaversion __P((struct aria_softc *));
175
176 void aria_set_mixer __P((struct aria_softc *, int));
177
178 void aria_mix_write __P((struct aria_softc *, int, int));
179 int aria_mix_read __P((struct aria_softc *, int));
180
181 int aria_mixer_set_port __P((void *, mixer_ctrl_t *));
182 int aria_mixer_get_port __P((void *, mixer_ctrl_t *));
183 int aria_mixer_query_devinfo __P((void *, mixer_devinfo_t *));
184
185 CFATTACH_DECL(aria, sizeof(struct aria_softc),
186 ariaprobe, ariaattach, NULL, NULL);
187
188 /* XXX temporary test for 1.3 */
189 #ifndef AudioNaux
190 /* 1.3 */
191 struct cfdriver aria_cd = {
192 NULL, "aria", DV_DULL
193 };
194 #endif
195
196 struct audio_device aria_device = {
197 "Aria 16(se)",
198 "x",
199 "aria"
200 };
201
202 /*
203 * Define our interface to the higher level audio driver.
204 */
205
206 const struct audio_hw_if aria_hw_if = {
207 ariaopen,
208 ariaclose,
209 NULL,
210 aria_query_encoding,
211 aria_set_params,
212 aria_round_blocksize,
213 aria_commit_settings,
214 NULL,
215 NULL,
216 aria_start_output,
217 aria_start_input,
218 aria_halt_input,
219 aria_halt_output,
220 NULL,
221 aria_getdev,
222 NULL,
223 aria_mixer_set_port,
224 aria_mixer_get_port,
225 aria_mixer_query_devinfo,
226 NULL,
227 NULL,
228 NULL,
229 NULL,
230 aria_get_props,
231 NULL,
232 NULL,
233 NULL,
234 };
235
236 /*
237 * Probe / attach routines.
238 */
239
240 /*
241 * Probe for the aria hardware.
242 */
243 int
244 ariaprobe(parent, cf, aux)
245 struct device *parent;
246 struct cfdata *cf;
247 void *aux;
248 {
249 bus_space_handle_t ioh;
250 struct isa_attach_args *ia = aux;
251
252 if (ia->ia_nio < 1)
253 return (0);
254 if (ia->ia_nirq < 1)
255 return (0);
256
257 if (ISA_DIRECT_CONFIG(ia))
258 return (0);
259
260 if (!ARIA_BASE_VALID(ia->ia_io[0].ir_addr)) {
261 printf("aria: configured iobase %d invalid\n",
262 ia->ia_io[0].ir_addr);
263 return 0;
264 }
265
266 if (!ARIA_IRQ_VALID(ia->ia_irq[0].ir_irq)) {
267 printf("aria: configured irq %d invalid\n",
268 ia->ia_irq[0].ir_irq);
269 return 0;
270 }
271
272 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, ARIADSP_NPORT,
273 0, &ioh)) {
274 DPRINTF(("aria: aria probe failed\n"));
275 return 0;
276 }
277
278 if (cf->cf_flags & 1)
279 aria_prometheus_kludge(ia, ioh);
280
281 if (ariareset(ia->ia_iot, ioh) != 0) {
282 DPRINTF(("aria: aria probe failed\n"));
283 bus_space_unmap(ia->ia_iot, ioh, ARIADSP_NPORT);
284 return 0;
285 }
286
287 bus_space_unmap(ia->ia_iot, ioh, ARIADSP_NPORT);
288
289 ia->ia_nio = 1;
290 ia->ia_io[0].ir_size = ARIADSP_NPORT;
291
292 ia->ia_nirq = 1;
293
294 ia->ia_niomem = 0;
295 ia->ia_ndrq = 0;
296
297 DPRINTF(("aria: aria probe succeeded\n"));
298 return 1;
299 }
300
301 /*
302 * I didn't call this a kludge for
303 * nothing. This is cribbed from
304 * ariainit, the author of that
305 * disassembled some code to discover
306 * how to set up the initial values of
307 * the card. Without this, the card
308 * is dead. (It will not respond to _any_
309 * input at all.)
310 *
311 * ariainit can be found (ftp) at:
312 * ftp://ftp.wi.leidenuniv.nl/pub/audio/aria/programming/contrib/ariainit.zip
313 * currently.
314 */
315
316 void
317 aria_prometheus_kludge(ia, ioh1)
318 struct isa_attach_args *ia;
319 bus_space_handle_t ioh1;
320 {
321 bus_space_tag_t iot;
322 bus_space_handle_t ioh;
323 u_short end;
324
325 DPRINTF(("aria: begin aria_prometheus_kludge\n"));
326
327 /* Begin Config Sequence */
328
329 iot = ia->ia_iot;
330 bus_space_map(iot, 0x200, 8, 0, &ioh);
331
332 bus_space_write_1(iot, ioh, 4, 0x4c);
333 bus_space_write_1(iot, ioh, 5, 0x42);
334 bus_space_write_1(iot, ioh, 6, 0x00);
335 bus_space_write_2(iot, ioh, 0, 0x0f);
336 bus_space_write_1(iot, ioh, 1, 0x00);
337 bus_space_write_2(iot, ioh, 0, 0x02);
338 bus_space_write_1(iot, ioh, 1, ia->ia_io[0].ir_addr>>2);
339
340 /*
341 * These next three lines set up the iobase
342 * and the irq; and disable the drq.
343 */
344
345 aria_do_kludge(iot, ioh, ioh1, 0x111,
346 ((ia->ia_io[0].ir_addr-0x280)>>2)+0xA0, 0xbf, 0xa0);
347 aria_do_kludge(iot, ioh, ioh1, 0x011,
348 ia->ia_irq[0].ir_irq-6, 0xf8, 0x00);
349 aria_do_kludge(iot, ioh, ioh1, 0x011, 0x00, 0xef, 0x00);
350
351 /* The rest of these lines just disable everything else */
352
353 aria_do_kludge(iot, ioh, ioh1, 0x113, 0x00, 0x88, 0x00);
354 aria_do_kludge(iot, ioh, ioh1, 0x013, 0x00, 0xf8, 0x00);
355 aria_do_kludge(iot, ioh, ioh1, 0x013, 0x00, 0xef, 0x00);
356 aria_do_kludge(iot, ioh, ioh1, 0x117, 0x00, 0x88, 0x00);
357 aria_do_kludge(iot, ioh, ioh1, 0x017, 0x00, 0xff, 0x00);
358
359 /* End Sequence */
360
361 bus_space_write_1(iot, ioh, 0, 0x0f);
362 end = bus_space_read_1(iot, ioh1, 0);
363 bus_space_write_2(iot, ioh, 0, 0x0f);
364 bus_space_write_1(iot, ioh, 1, end|0x80);
365 bus_space_read_1(iot, ioh, 0);
366
367 bus_space_unmap(iot, ioh, 8);
368 /*
369 * This delay is necessary for some reason,
370 * at least it would crash, and sometimes not
371 * probe properly if it did not exist.
372 */
373 delay(1000000);
374 }
375
376 void
377 aria_do_kludge(iot, ioh, ioh1, func, bits, and, or)
378 bus_space_tag_t iot;
379 bus_space_handle_t ioh;
380 bus_space_handle_t ioh1;
381 u_short func;
382 u_short bits;
383 u_short and;
384 u_short or;
385 {
386 u_int i;
387 if (func & 0x100) {
388 func &= ~0x100;
389 if (bits) {
390 bus_space_write_2(iot, ioh, 0, func-1);
391 bus_space_write_1(iot, ioh, 1, bits);
392 }
393 } else
394 or |= bits;
395
396 bus_space_write_1(iot, ioh, 0, func);
397 i = bus_space_read_1(iot, ioh1, 0);
398 bus_space_write_2(iot, ioh, 0, func);
399 bus_space_write_1(iot, ioh, 1, (i&and) | or);
400 }
401
402 /*
403 * Attach hardware to driver, attach hardware driver to audio
404 * pseudo-device driver.
405 */
406 void
407 ariaattach(parent, self, aux)
408 struct device *parent, *self;
409 void *aux;
410 {
411 bus_space_handle_t ioh;
412 struct aria_softc *sc = (void *)self;
413 struct isa_attach_args *ia = aux;
414 u_short i;
415
416 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, ARIADSP_NPORT,
417 0, &ioh))
418 panic("%s: can map io port range", self->dv_xname);
419
420 sc->sc_iot = ia->ia_iot;
421 sc->sc_ioh = ioh;
422 sc->sc_ic = ia->ia_ic;
423
424 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
425 IST_EDGE, IPL_AUDIO, aria_intr, sc);
426
427 DPRINTF(("isa_intr_establish() returns (%x)\n", (unsigned) sc->sc_ih));
428
429 i = aria_getdspmem(sc, ARIAA_HARDWARE_A);
430
431 sc->sc_hardware = 0;
432 sc->sc_hardware |= ((i>>13)&0x01)==1 ? ARIA_TELEPHONE:0;
433 sc->sc_hardware |= (((i>>5)&0x07))==0x04 ? ARIA_MIXER:0;
434 sc->sc_hardware |= (aria_getdspmem(sc, ARIAA_MODEL_A)>=1)?ARIA_MODEL:0;
435
436 sc->sc_open = 0;
437 sc->sc_play = 0;
438 sc->sc_record = 0;
439 sc->sc_rate = 7875;
440 sc->sc_chans = 1;
441 sc->sc_blocksize = 1024;
442 sc->sc_precision = 8;
443 sc->sc_rintr = 0;
444 sc->sc_rarg = 0;
445 sc->sc_pintr = 0;
446 sc->sc_parg = 0;
447 sc->sc_gain[0] = 127;
448 sc->sc_gain[1] = 127;
449
450 for (i=0; i<6; i++) {
451 if (i == ARIAMIX_TEL_LVL)
452 sc->aria_mix[i].num_channels = 1;
453 else
454 sc->aria_mix[i].num_channels = 2;
455 sc->aria_mix[i].level[0] = 127;
456 sc->aria_mix[i].level[1] = 127;
457 }
458
459 sc->ariamix_master.num_channels = 2;
460 sc->ariamix_master.level[0] = 222;
461 sc->ariamix_master.level[1] = 222;
462 sc->ariamix_master.bass[0] = 127;
463 sc->ariamix_master.bass[1] = 127;
464 sc->ariamix_master.treble[0] = 127;
465 sc->ariamix_master.treble[1] = 127;
466 sc->aria_mix_source = 0;
467
468 aria_commit_settings(sc);
469
470 printf(": dsp %s", (ARIA_MODEL&sc->sc_hardware)?"SC18026":"SC18025");
471 if (ARIA_TELEPHONE&sc->sc_hardware)
472 printf(", tel");
473 if (ARIA_MIXER&sc->sc_hardware)
474 printf(", SC18075 mixer");
475 printf("\n");
476
477 snprintf(aria_device.version, sizeof(aria_device.version), "%s",
478 ARIA_MODEL & sc->sc_hardware ? "SC18026" : "SC18025");
479
480 audio_attach_mi(&aria_hw_if, (void *)sc, &sc->sc_dev);
481 }
482
483 /*
484 * Various routines to interface to higher level audio driver
485 */
486
487 int
488 ariaopen(addr, flags)
489 void *addr;
490 int flags;
491 {
492 struct aria_softc *sc = addr;
493
494 DPRINTF(("ariaopen() called\n"));
495
496 if (!sc)
497 return ENXIO;
498
499 if (flags&FREAD)
500 sc->sc_open |= ARIAR_OPEN_RECORD;
501 if (flags&FWRITE)
502 sc->sc_open |= ARIAR_OPEN_PLAY;
503
504 return 0;
505 }
506
507 int
508 aria_getdev(addr, retp)
509 void *addr;
510 struct audio_device *retp;
511 {
512 *retp = aria_device;
513 return 0;
514 }
515
516 /*
517 * Various routines to interface to higher level audio driver
518 */
519
520 int
521 aria_query_encoding(addr, fp)
522 void *addr;
523 struct audio_encoding *fp;
524 {
525 struct aria_softc *sc = addr;
526
527 switch (fp->index) {
528 case 0:
529 strcpy(fp->name, AudioEmulaw);
530 fp->encoding = AUDIO_ENCODING_ULAW;
531 fp->precision = 8;
532 if ((ARIA_MODEL&sc->sc_hardware) == 0)
533 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
534 break;
535 case 1:
536 strcpy(fp->name, AudioEalaw);
537 fp->encoding = AUDIO_ENCODING_ALAW;
538 fp->precision = 8;
539 if ((ARIA_MODEL&sc->sc_hardware) == 0)
540 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
541 break;
542 case 2:
543 strcpy(fp->name, AudioEslinear);
544 fp->encoding = AUDIO_ENCODING_SLINEAR;
545 fp->precision = 8;
546 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
547 break;
548 case 3:
549 strcpy(fp->name, AudioEslinear_le);
550 fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
551 fp->precision = 16;
552 fp->flags = 0;
553 break;
554 case 4:
555 strcpy(fp->name, AudioEslinear_be);
556 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
557 fp->precision = 16;
558 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
559 break;
560 case 5:
561 strcpy(fp->name, AudioEulinear);
562 fp->encoding = AUDIO_ENCODING_ULINEAR;
563 fp->precision = 8;
564 fp->flags = 0;
565 break;
566 case 6:
567 strcpy(fp->name, AudioEulinear_le);
568 fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
569 fp->precision = 16;
570 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
571 break;
572 case 7:
573 strcpy(fp->name, AudioEulinear_be);
574 fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
575 fp->precision = 16;
576 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
577 break;
578 default:
579 return(EINVAL);
580 /*NOTREACHED*/
581 }
582
583 return (0);
584 }
585
586 /*
587 * Store blocksize in bytes.
588 */
589
590 int
591 aria_round_blocksize(addr, blk, mode, param)
592 void *addr;
593 int blk;
594 int mode;
595 const audio_params_t *param;
596 {
597 int i;
598 #if 0 /* XXX -- this is being a tad bit of a problem... */
599 for (i=64; i<1024; i*=2)
600 if (blk <= i)
601 break;
602 #else
603 i = 1024;
604 #endif
605 return(i);
606 }
607
608 int
609 aria_get_props(addr)
610 void *addr;
611 {
612 return AUDIO_PROP_FULLDUPLEX;
613 }
614
615 int
616 aria_set_params(addr, setmode, usemode, p, r, pfil, rfil)
617 void *addr;
618 int setmode, usemode;
619 audio_params_t *p, *r;
620 stream_filter_list_t *pfil, *rfil;
621 {
622 audio_params_t hw;
623 struct aria_softc *sc = addr;
624
625 switch(p->encoding) {
626 case AUDIO_ENCODING_ULAW:
627 case AUDIO_ENCODING_ALAW:
628 case AUDIO_ENCODING_SLINEAR:
629 case AUDIO_ENCODING_SLINEAR_LE:
630 case AUDIO_ENCODING_SLINEAR_BE:
631 case AUDIO_ENCODING_ULINEAR:
632 case AUDIO_ENCODING_ULINEAR_LE:
633 case AUDIO_ENCODING_ULINEAR_BE:
634 break;
635 default:
636 return (EINVAL);
637 }
638
639 if (p->sample_rate <= 9450)
640 p->sample_rate = 7875;
641 else if (p->sample_rate <= 13387)
642 p->sample_rate = 11025;
643 else if (p->sample_rate <= 18900)
644 p->sample_rate = 15750;
645 else if (p->sample_rate <= 26775)
646 p->sample_rate = 22050;
647 else if (p->sample_rate <= 37800)
648 p->sample_rate = 31500;
649 else
650 p->sample_rate = 44100;
651
652 hw = *p;
653 sc->sc_encoding = p->encoding;
654 sc->sc_precision = p->precision;
655 sc->sc_chans = p->channels;
656 sc->sc_rate = p->sample_rate;
657
658 switch(p->encoding) {
659 case AUDIO_ENCODING_ULAW:
660 if ((ARIA_MODEL&sc->sc_hardware) == 0) {
661 hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
662 stream_filter_list_append(pfil, mulaw_to_linear8, &hw);
663 stream_filter_list_append(rfil, linear8_to_mulaw, &hw);
664 }
665 break;
666 case AUDIO_ENCODING_ALAW:
667 if ((ARIA_MODEL&sc->sc_hardware) == 0) {
668 hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
669 stream_filter_list_append(pfil, alaw_to_linear8, &hw);
670 stream_filter_list_append(rfil, linear8_to_alaw, &hw);
671 }
672 break;
673 case AUDIO_ENCODING_SLINEAR:
674 hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
675 stream_filter_list_append(pfil, change_sign8, &hw);
676 stream_filter_list_append(rfil, change_sign8, &hw);
677 break;
678 case AUDIO_ENCODING_ULINEAR_LE:
679 hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
680 stream_filter_list_append(pfil, change_sign16, &hw);
681 stream_filter_list_append(rfil, change_sign16, &hw);
682 break;
683 case AUDIO_ENCODING_SLINEAR_BE:
684 hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
685 stream_filter_list_append(pfil, swap_bytes, &hw);
686 stream_filter_list_append(rfil, swap_bytes, &hw);
687 break;
688 case AUDIO_ENCODING_ULINEAR_BE:
689 hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
690 stream_filter_list_append(pfil, swap_bytes_change_sign16, &hw);
691 stream_filter_list_append(rfil, swap_bytes_change_sign16, &hw);
692 break;
693 }
694
695 return 0;
696 }
697
698 /*
699 * This is where all of the twiddling goes on.
700 */
701
702 int
703 aria_commit_settings(addr)
704 void *addr;
705 {
706 struct aria_softc *sc = addr;
707 bus_space_tag_t iot = sc->sc_iot;
708 bus_space_handle_t ioh = sc->sc_ioh;
709 static u_char tones[16] =
710 { 7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15 };
711 u_short format;
712 u_short left, right;
713 u_short samp;
714 u_char i;
715
716 DPRINTF(("aria_commit_settings\n"));
717
718 switch (sc->sc_rate) {
719 case 7875: format = 0x00; samp = 0x60; break;
720 case 11025: format = 0x00; samp = 0x40; break;
721 case 15750: format = 0x10; samp = 0x60; break;
722 case 22050: format = 0x10; samp = 0x40; break;
723 case 31500: format = 0x10; samp = 0x20; break;
724 case 44100: format = 0x20; samp = 0x00; break;
725 default: format = 0x00; samp = 0x40; break;/* XXX can we get here? */
726 }
727
728 if ((ARIA_MODEL&sc->sc_hardware) != 0) {
729 format |= (sc->sc_encoding==AUDIO_ENCODING_ULAW)?0x06:0x00;
730 format |= (sc->sc_encoding==AUDIO_ENCODING_ALAW)?0x08:0x00;
731 }
732
733 format |= (sc->sc_precision==16)?0x02:0x00;
734 format |= (sc->sc_chans==2)?1:0;
735 samp |= bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ~0x60;
736
737 aria_sendcmd(sc, ARIADSPC_FORMAT, format, -1, -1);
738 bus_space_write_2(iot, ioh, ARIADSP_CONTROL, samp);
739
740 if (sc->sc_hardware&ARIA_MIXER) {
741 for (i = 0; i < 6; i++)
742 aria_set_mixer(sc, i);
743
744 if (sc->sc_chans==2) {
745 aria_sendcmd(sc, ARIADSPC_CHAN_VOL, ARIAR_PLAY_CHAN,
746 ((sc->sc_gain[0]+sc->sc_gain[1])/2)<<7,
747 -1);
748 aria_sendcmd(sc, ARIADSPC_CHAN_PAN, ARIAR_PLAY_CHAN,
749 (sc->sc_gain[0]-sc->sc_gain[1])/4+0x40,
750 -1);
751 } else {
752 aria_sendcmd(sc, ARIADSPC_CHAN_VOL, ARIAR_PLAY_CHAN,
753 sc->sc_gain[0]<<7, -1);
754 aria_sendcmd(sc, ARIADSPC_CHAN_PAN, ARIAR_PLAY_CHAN,
755 0x40, -1);
756 }
757
758 aria_sendcmd(sc, ARIADSPC_MASMONMODE,
759 sc->ariamix_master.num_channels != 2, -1, -1);
760
761 aria_sendcmd(sc, ARIADSPC_MIXERVOL, 0x0004,
762 sc->ariamix_master.level[0] << 7,
763 sc->ariamix_master.level[1] << 7);
764
765 /* Convert treble/bass from byte to soundcard style */
766
767 left = (tones[(sc->ariamix_master.treble[0]>>4)&0x0f]<<8) |
768 tones[(sc->ariamix_master.bass[0]>>4)&0x0f];
769 right = (tones[(sc->ariamix_master.treble[1]>>4)&0x0f]<<8) |
770 tones[(sc->ariamix_master.bass[1]>>4)&0x0f];
771
772 aria_sendcmd(sc, ARIADSPC_TONE, left, right, -1);
773 }
774
775 aria_sendcmd(sc, ARIADSPC_BLOCKSIZE, sc->sc_blocksize/2, -1, -1);
776
777 /*
778 * If we think that the card is recording or playing, start it up again here.
779 * Some of the previous commands turn the channels off.
780 */
781
782 if (sc->sc_record&(1<<ARIAR_RECORD_CHAN))
783 aria_sendcmd(sc, ARIADSPC_START_REC, ARIAR_RECORD_CHAN, -1,-1);
784
785 if (sc->sc_play&(1<<ARIAR_PLAY_CHAN))
786 aria_sendcmd(sc, ARIADSPC_START_PLAY, ARIAR_PLAY_CHAN, -1, -1);
787
788 return(0);
789 }
790
791 void
792 aria_set_mixer(sc, i)
793 struct aria_softc *sc;
794 int i;
795 {
796 u_char source;
797 switch(i) {
798 case ARIAMIX_MIC_LVL: source = 0x0001; break;
799 case ARIAMIX_CD_LVL: source = 0x0002; break;
800 case ARIAMIX_LINE_IN_LVL: source = 0x0008; break;
801 case ARIAMIX_TEL_LVL: source = 0x0020; break;
802 case ARIAMIX_AUX_LVL: source = 0x0010; break;
803 case ARIAMIX_DAC_LVL: source = 0x0004; break;
804 default: source = 0x0000; break;
805 }
806
807 if (source != 0x0000 && source != 0x0004) {
808 if (sc->aria_mix[i].mute == 1)
809 aria_sendcmd(sc, ARIADSPC_INPMONMODE, source, 3, -1);
810 else
811 aria_sendcmd(sc, ARIADSPC_INPMONMODE, source,
812 sc->aria_mix[i].num_channels != 2, -1);
813
814 aria_sendcmd(sc, ARIADSPC_INPMONMODE, 0x8000|source,
815 sc->aria_mix[i].num_channels != 2, -1);
816 aria_sendcmd(sc, ARIADSPC_MIXERVOL, source,
817 sc->aria_mix[i].level[0] << 7,
818 sc->aria_mix[i].level[1] << 7);
819 }
820
821 if (sc->aria_mix_source == i) {
822 aria_sendcmd(sc, ARIADSPC_ADCSOURCE, source, -1, -1);
823
824 if (sc->sc_open & ARIAR_OPEN_RECORD)
825 aria_sendcmd(sc, ARIADSPC_ADCCONTROL, 1, -1, -1);
826 else
827 aria_sendcmd(sc, ARIADSPC_ADCCONTROL, 0, -1, -1);
828 }
829 }
830
831 void
832 ariaclose(addr)
833 void *addr;
834 {
835 struct aria_softc *sc = addr;
836
837 DPRINTF(("aria_close sc=0x%x\n", (unsigned) sc));
838
839 sc->sc_open = 0;
840
841 if (aria_reset(sc) != 0) {
842 delay(500);
843 aria_reset(sc);
844 }
845 }
846
847 /*
848 * Reset the hardware.
849 */
850
851 int ariareset(iot, ioh)
852 bus_space_tag_t iot;
853 bus_space_handle_t ioh;
854 {
855 struct aria_softc tmp, *sc = &tmp;
856
857 sc->sc_iot = iot;
858 sc->sc_ioh = ioh;
859 return aria_reset(sc);
860 }
861
862 int
863 aria_reset(sc)
864 struct aria_softc *sc;
865 {
866 bus_space_tag_t iot = sc->sc_iot;
867 bus_space_handle_t ioh = sc->sc_ioh;
868 int fail=0;
869 int i;
870
871 bus_space_write_2(iot, ioh, ARIADSP_CONTROL,
872 ARIAR_ARIA_SYNTH | ARIAR_SR22K|ARIAR_DSPINTWR);
873 aria_putdspmem(sc, 0x6102, 0);
874
875 fail |= aria_sendcmd(sc, ARIADSPC_SYSINIT, 0x0000, 0x0000, 0x0000);
876
877 for (i=0; i < ARIAR_NPOLL; i++)
878 if (aria_getdspmem(sc, ARIAA_TASK_A) == 1)
879 break;
880
881 bus_space_write_2(iot, ioh, ARIADSP_CONTROL,
882 ARIAR_ARIA_SYNTH|ARIAR_SR22K | ARIAR_DSPINTWR |
883 ARIAR_PCINTWR);
884 fail |= aria_sendcmd(sc, ARIADSPC_MODE, ARIAV_MODE_NO_SYNTH,-1,-1);
885
886 return (fail);
887 }
888
889 /*
890 * Lower-level routines
891 */
892
893 void
894 aria_putdspmem(sc, loc, val)
895 struct aria_softc *sc;
896 u_short loc;
897 u_short val;
898 {
899 bus_space_tag_t iot = sc->sc_iot;
900 bus_space_handle_t ioh = sc->sc_ioh;
901 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, loc);
902 bus_space_write_2(iot, ioh, ARIADSP_DMADATA, val);
903 }
904
905 u_short
906 aria_getdspmem(sc, loc)
907 struct aria_softc *sc;
908 u_short loc;
909 {
910 bus_space_tag_t iot = sc->sc_iot;
911 bus_space_handle_t ioh = sc->sc_ioh;
912 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, loc);
913 return bus_space_read_2(iot, ioh, ARIADSP_DMADATA);
914 }
915
916 /*
917 * aria_sendcmd()
918 * each full DSP command is unified into this
919 * function.
920 */
921
922 #define ARIASEND(data, flag) \
923 for (i = ARIAR_NPOLL; \
924 (bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ARIAR_BUSY) && i>0; \
925 i--) \
926 ; \
927 if (bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ARIAR_BUSY) \
928 fail |= flag; \
929 bus_space_write_2(iot, ioh, ARIADSP_WRITE, (u_short)data)
930
931 int
932 aria_sendcmd(sc, command, arg1, arg2, arg3)
933 struct aria_softc *sc;
934 u_short command;
935 int arg1;
936 int arg2;
937 int arg3;
938 {
939 bus_space_tag_t iot = sc->sc_iot;
940 bus_space_handle_t ioh = sc->sc_ioh;
941 int i, fail = 0;
942
943 ARIASEND(command, 1);
944 if (arg1 != -1) {
945 ARIASEND(arg1, 2);
946 }
947 if (arg2 != -1) {
948 ARIASEND(arg2, 4);
949 }
950 if (arg3 != -1) {
951 ARIASEND(arg3, 8);
952 }
953 ARIASEND(ARIADSPC_TERM, 16);
954
955 if (fail) {
956 sc->sc_sendcmd_err++;
957 #ifdef AUDIO_DEBUG
958 DPRINTF(("aria_sendcmd: failure=(%d) cmd=(0x%x) fail=(0x%x)\n",
959 sc->sc_sendcmd_err, command, fail));
960 #endif
961 return -1;
962 }
963
964 return 0;
965 }
966 #undef ARIASEND
967
968 int
969 aria_halt_input(addr)
970 void *addr;
971 {
972 struct aria_softc *sc = addr;
973
974 DPRINTF(("aria_halt_input\n"));
975
976 if (sc->sc_record & (1<<0)) {
977 aria_sendcmd(sc, ARIADSPC_STOP_REC, 0, -1, -1);
978 sc->sc_record &= ~(1<<0);
979 sc->sc_rdiobuffer = 0;
980 }
981
982 return(0);
983 }
984
985 int
986 aria_halt_output(addr)
987 void *addr;
988 {
989 struct aria_softc *sc = addr;
990
991 DPRINTF(("aria_halt_output\n"));
992
993 if (sc->sc_play & (1<<1)) {
994 aria_sendcmd(sc, ARIADSPC_STOP_PLAY, 1, -1, -1);
995 sc->sc_play &= ~(1<<1);
996 sc->sc_pdiobuffer = 0;
997 }
998
999 return(0);
1000 }
1001
1002 /*
1003 * Here we just set up the buffers. If we receive
1004 * an interrupt without these set, it is ignored.
1005 */
1006
1007 int
1008 aria_start_input(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 aria_softc *sc = addr;
1016
1017 DPRINTF(("aria_start_input %d @ %x\n", cc, (unsigned) p));
1018
1019 if (cc != sc->sc_blocksize) {
1020 DPRINTF(("aria_start_input reqsize %d not sc_blocksize %d\n",
1021 cc, sc->sc_blocksize));
1022 return EINVAL;
1023 }
1024
1025 sc->sc_rarg = arg;
1026 sc->sc_rintr = intr;
1027 sc->sc_rdiobuffer = p;
1028
1029 if (!(sc->sc_record&(1<<ARIAR_RECORD_CHAN))) {
1030 aria_sendcmd(sc, ARIADSPC_START_REC, ARIAR_RECORD_CHAN, -1,-1);
1031 sc->sc_record |= (1<<ARIAR_RECORD_CHAN);
1032 }
1033
1034 return 0;
1035 }
1036
1037 int
1038 aria_start_output(addr, p, cc, intr, arg)
1039 void *addr;
1040 void *p;
1041 int cc;
1042 void (*intr) __P((void *));
1043 void *arg;
1044 {
1045 struct aria_softc *sc = addr;
1046
1047 DPRINTF(("aria_start_output %d @ %x\n", cc, (unsigned) p));
1048
1049 if (cc != sc->sc_blocksize) {
1050 DPRINTF(("aria_start_output reqsize %d not sc_blocksize %d\n",
1051 cc, sc->sc_blocksize));
1052 return EINVAL;
1053 }
1054
1055 sc->sc_parg = arg;
1056 sc->sc_pintr = intr;
1057 sc->sc_pdiobuffer = p;
1058
1059 if (!(sc->sc_play&(1<<ARIAR_PLAY_CHAN))) {
1060 aria_sendcmd(sc, ARIADSPC_START_PLAY, ARIAR_PLAY_CHAN, -1, -1);
1061 sc->sc_play |= (1<<ARIAR_PLAY_CHAN);
1062 }
1063
1064 return 0;
1065 }
1066
1067 /*
1068 * Process an interrupt. This should be a
1069 * request (from the card) to write or read
1070 * samples.
1071 */
1072 int
1073 aria_intr(arg)
1074 void *arg;
1075 {
1076 struct aria_softc *sc = arg;
1077 bus_space_tag_t iot = sc->sc_iot;
1078 bus_space_handle_t ioh = sc->sc_ioh;
1079 u_short *pdata = sc->sc_pdiobuffer;
1080 u_short *rdata = sc->sc_rdiobuffer;
1081 u_short address;
1082
1083 #if 0 /* XXX -- BAD BAD BAD (That this is #define'd out */
1084 DPRINTF(("Checking to see if this is our intr\n"));
1085
1086 if ((inw(iobase) & 1) != 0x1)
1087 return 0; /* not for us */
1088 #endif
1089
1090 sc->sc_interrupts++;
1091
1092 DPRINTF(("aria_intr\n"));
1093
1094 if ((sc->sc_open & ARIAR_OPEN_PLAY) && (pdata!=NULL)) {
1095 DPRINTF(("aria_intr play=(%x)\n", (unsigned) pdata));
1096 address = 0x8000 - 2*(sc->sc_blocksize);
1097 address+= aria_getdspmem(sc, ARIAA_PLAY_FIFO_A);
1098 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, address);
1099 bus_space_write_multi_2(iot, ioh, ARIADSP_DMADATA, pdata,
1100 sc->sc_blocksize / 2);
1101 if (sc->sc_pintr != NULL)
1102 (*sc->sc_pintr)(sc->sc_parg);
1103 }
1104
1105 if ((sc->sc_open & ARIAR_OPEN_RECORD) && (rdata!=NULL)) {
1106 DPRINTF(("aria_intr record=(%x)\n", (unsigned) rdata));
1107 address = 0x8000 - (sc->sc_blocksize);
1108 address+= aria_getdspmem(sc, ARIAA_REC_FIFO_A);
1109 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, address);
1110 bus_space_read_multi_2(iot, ioh, ARIADSP_DMADATA, rdata,
1111 sc->sc_blocksize / 2);
1112 if (sc->sc_rintr != NULL)
1113 (*sc->sc_rintr)(sc->sc_rarg);
1114 }
1115
1116 aria_sendcmd(sc, ARIADSPC_TRANSCOMPLETE, -1, -1, -1);
1117
1118 return 1;
1119 }
1120
1121 int
1122 aria_mixer_set_port(addr, cp)
1123 void *addr;
1124 mixer_ctrl_t *cp;
1125 {
1126 struct aria_softc *sc = addr;
1127 int error = EINVAL;
1128
1129 DPRINTF(("aria_mixer_set_port\n"));
1130
1131 /* This could be done better, no mixer still has some controls. */
1132 if (!(ARIA_MIXER & sc->sc_hardware))
1133 return ENXIO;
1134
1135 if (cp->type == AUDIO_MIXER_VALUE) {
1136 mixer_level_t *mv = &cp->un.value;
1137 switch (cp->dev) {
1138 case ARIAMIX_MIC_LVL:
1139 if (mv->num_channels == 1 || mv->num_channels == 2) {
1140 sc->aria_mix[ARIAMIX_MIC_LVL].num_channels =
1141 mv->num_channels;
1142 sc->aria_mix[ARIAMIX_MIC_LVL].level[0] =
1143 mv->level[0];
1144 sc->aria_mix[ARIAMIX_MIC_LVL].level[1] =
1145 mv->level[1];
1146 error = 0;
1147 }
1148 break;
1149
1150 case ARIAMIX_LINE_IN_LVL:
1151 if (mv->num_channels == 1 || mv->num_channels == 2) {
1152 sc->aria_mix[ARIAMIX_LINE_IN_LVL].num_channels=
1153 mv->num_channels;
1154 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[0] =
1155 mv->level[0];
1156 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[1] =
1157 mv->level[1];
1158 error = 0;
1159 }
1160 break;
1161
1162 case ARIAMIX_CD_LVL:
1163 if (mv->num_channels == 1 || mv->num_channels == 2) {
1164 sc->aria_mix[ARIAMIX_CD_LVL].num_channels =
1165 mv->num_channels;
1166 sc->aria_mix[ARIAMIX_CD_LVL].level[0] =
1167 mv->level[0];
1168 sc->aria_mix[ARIAMIX_CD_LVL].level[1] =
1169 mv->level[1];
1170 error = 0;
1171 }
1172 break;
1173
1174 case ARIAMIX_TEL_LVL:
1175 if (mv->num_channels == 1) {
1176 sc->aria_mix[ARIAMIX_TEL_LVL].num_channels =
1177 mv->num_channels;
1178 sc->aria_mix[ARIAMIX_TEL_LVL].level[0] =
1179 mv->level[0];
1180 error = 0;
1181 }
1182 break;
1183
1184 case ARIAMIX_DAC_LVL:
1185 if (mv->num_channels == 1 || mv->num_channels == 2) {
1186 sc->aria_mix[ARIAMIX_DAC_LVL].num_channels =
1187 mv->num_channels;
1188 sc->aria_mix[ARIAMIX_DAC_LVL].level[0] =
1189 mv->level[0];
1190 sc->aria_mix[ARIAMIX_DAC_LVL].level[1] =
1191 mv->level[1];
1192 error = 0;
1193 }
1194 break;
1195
1196 case ARIAMIX_AUX_LVL:
1197 if (mv->num_channels == 1 || mv->num_channels == 2) {
1198 sc->aria_mix[ARIAMIX_AUX_LVL].num_channels =
1199 mv->num_channels;
1200 sc->aria_mix[ARIAMIX_AUX_LVL].level[0] =
1201 mv->level[0];
1202 sc->aria_mix[ARIAMIX_AUX_LVL].level[1] =
1203 mv->level[1];
1204 error = 0;
1205 }
1206 break;
1207
1208 case ARIAMIX_MASTER_LVL:
1209 if (mv->num_channels == 1 || mv->num_channels == 2) {
1210 sc->ariamix_master.num_channels =
1211 mv->num_channels;
1212 sc->ariamix_master.level[0] = mv->level[0];
1213 sc->ariamix_master.level[1] = mv->level[1];
1214 error = 0;
1215 }
1216 break;
1217
1218 case ARIAMIX_MASTER_TREBLE:
1219 if (mv->num_channels == 2) {
1220 sc->ariamix_master.treble[0] =
1221 mv->level[0] == 0 ? 1 : mv->level[0];
1222 sc->ariamix_master.treble[1] =
1223 mv->level[1] == 0 ? 1 : mv->level[1];
1224 error = 0;
1225 }
1226 break;
1227 case ARIAMIX_MASTER_BASS:
1228 if (mv->num_channels == 2) {
1229 sc->ariamix_master.bass[0] =
1230 mv->level[0] == 0 ? 1 : mv->level[0];
1231 sc->ariamix_master.bass[1] =
1232 mv->level[1] == 0 ? 1 : mv->level[1];
1233 error = 0;
1234 }
1235 break;
1236 case ARIAMIX_OUT_LVL:
1237 if (mv->num_channels == 1 || mv->num_channels == 2) {
1238 sc->sc_gain[0] = mv->level[0];
1239 sc->sc_gain[1] = mv->level[1];
1240 error = 0;
1241 }
1242 break;
1243 default:
1244 }
1245 }
1246
1247 if (cp->type == AUDIO_MIXER_ENUM)
1248 switch(cp->dev) {
1249 case ARIAMIX_RECORD_SOURCE:
1250 if (cp->un.ord>=0 && cp->un.ord<=6) {
1251 sc->aria_mix_source = cp->un.ord;
1252 error = 0;
1253 }
1254 break;
1255
1256 case ARIAMIX_MIC_MUTE:
1257 if (cp->un.ord == 0 || cp->un.ord == 1) {
1258 sc->aria_mix[ARIAMIX_MIC_LVL].mute =cp->un.ord;
1259 error = 0;
1260 }
1261 break;
1262
1263 case ARIAMIX_LINE_IN_MUTE:
1264 if (cp->un.ord == 0 || cp->un.ord == 1) {
1265 sc->aria_mix[ARIAMIX_LINE_IN_LVL].mute =
1266 cp->un.ord;
1267 error = 0;
1268 }
1269 break;
1270
1271 case ARIAMIX_CD_MUTE:
1272 if (cp->un.ord == 0 || cp->un.ord == 1) {
1273 sc->aria_mix[ARIAMIX_CD_LVL].mute = cp->un.ord;
1274 error = 0;
1275 }
1276 break;
1277
1278 case ARIAMIX_DAC_MUTE:
1279 if (cp->un.ord == 0 || cp->un.ord == 1) {
1280 sc->aria_mix[ARIAMIX_DAC_LVL].mute =cp->un.ord;
1281 error = 0;
1282 }
1283 break;
1284
1285 case ARIAMIX_AUX_MUTE:
1286 if (cp->un.ord == 0 || cp->un.ord == 1) {
1287 sc->aria_mix[ARIAMIX_AUX_LVL].mute =cp->un.ord;
1288 error = 0;
1289 }
1290 break;
1291
1292 case ARIAMIX_TEL_MUTE:
1293 if (cp->un.ord == 0 || cp->un.ord == 1) {
1294 sc->aria_mix[ARIAMIX_TEL_LVL].mute =cp->un.ord;
1295 error = 0;
1296 }
1297 break;
1298
1299 default:
1300 /* NOTREACHED */
1301 return ENXIO;
1302 }
1303
1304 return(error);
1305 }
1306
1307 int
1308 aria_mixer_get_port(addr, cp)
1309 void *addr;
1310 mixer_ctrl_t *cp;
1311 {
1312 struct aria_softc *sc = addr;
1313 int error = EINVAL;
1314
1315 DPRINTF(("aria_mixer_get_port\n"));
1316
1317 /* This could be done better, no mixer still has some controls. */
1318 if (!(ARIA_MIXER&sc->sc_hardware))
1319 return ENXIO;
1320
1321 switch (cp->dev) {
1322 case ARIAMIX_MIC_LVL:
1323 if (cp->type == AUDIO_MIXER_VALUE) {
1324 cp->un.value.num_channels =
1325 sc->aria_mix[ARIAMIX_MIC_LVL].num_channels;
1326 cp->un.value.level[0] =
1327 sc->aria_mix[ARIAMIX_MIC_LVL].level[0];
1328 cp->un.value.level[1] =
1329 sc->aria_mix[ARIAMIX_MIC_LVL].level[1];
1330 error = 0;
1331 }
1332 break;
1333
1334 case ARIAMIX_LINE_IN_LVL:
1335 if (cp->type == AUDIO_MIXER_VALUE) {
1336 cp->un.value.num_channels =
1337 sc->aria_mix[ARIAMIX_LINE_IN_LVL].num_channels;
1338 cp->un.value.level[0] =
1339 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[0];
1340 cp->un.value.level[1] =
1341 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[1];
1342 error = 0;
1343 }
1344 break;
1345
1346 case ARIAMIX_CD_LVL:
1347 if (cp->type == AUDIO_MIXER_VALUE) {
1348 cp->un.value.num_channels =
1349 sc->aria_mix[ARIAMIX_CD_LVL].num_channels;
1350 cp->un.value.level[0] =
1351 sc->aria_mix[ARIAMIX_CD_LVL].level[0];
1352 cp->un.value.level[1] =
1353 sc->aria_mix[ARIAMIX_CD_LVL].level[1];
1354 error = 0;
1355 }
1356 break;
1357
1358 case ARIAMIX_TEL_LVL:
1359 if (cp->type == AUDIO_MIXER_VALUE) {
1360 cp->un.value.num_channels =
1361 sc->aria_mix[ARIAMIX_TEL_LVL].num_channels;
1362 cp->un.value.level[0] =
1363 sc->aria_mix[ARIAMIX_TEL_LVL].level[0];
1364 error = 0;
1365 }
1366 break;
1367 case ARIAMIX_DAC_LVL:
1368 if (cp->type == AUDIO_MIXER_VALUE) {
1369 cp->un.value.num_channels =
1370 sc->aria_mix[ARIAMIX_DAC_LVL].num_channels;
1371 cp->un.value.level[0] =
1372 sc->aria_mix[ARIAMIX_DAC_LVL].level[0];
1373 cp->un.value.level[1] =
1374 sc->aria_mix[ARIAMIX_DAC_LVL].level[1];
1375 error = 0;
1376 }
1377 break;
1378
1379 case ARIAMIX_AUX_LVL:
1380 if (cp->type == AUDIO_MIXER_VALUE) {
1381 cp->un.value.num_channels =
1382 sc->aria_mix[ARIAMIX_AUX_LVL].num_channels;
1383 cp->un.value.level[0] =
1384 sc->aria_mix[ARIAMIX_AUX_LVL].level[0];
1385 cp->un.value.level[1] =
1386 sc->aria_mix[ARIAMIX_AUX_LVL].level[1];
1387 error = 0;
1388 }
1389 break;
1390
1391 case ARIAMIX_MIC_MUTE:
1392 if (cp->type == AUDIO_MIXER_ENUM) {
1393 cp->un.ord = sc->aria_mix[ARIAMIX_MIC_LVL].mute;
1394 error = 0;
1395 }
1396 break;
1397
1398 case ARIAMIX_LINE_IN_MUTE:
1399 if (cp->type == AUDIO_MIXER_ENUM) {
1400 cp->un.ord = sc->aria_mix[ARIAMIX_LINE_IN_LVL].mute;
1401 error = 0;
1402 }
1403 break;
1404
1405 case ARIAMIX_CD_MUTE:
1406 if (cp->type == AUDIO_MIXER_ENUM) {
1407 cp->un.ord = sc->aria_mix[ARIAMIX_CD_LVL].mute;
1408 error = 0;
1409 }
1410 break;
1411
1412 case ARIAMIX_DAC_MUTE:
1413 if (cp->type == AUDIO_MIXER_ENUM) {
1414 cp->un.ord = sc->aria_mix[ARIAMIX_DAC_LVL].mute;
1415 error = 0;
1416 }
1417 break;
1418
1419 case ARIAMIX_AUX_MUTE:
1420 if (cp->type == AUDIO_MIXER_ENUM) {
1421 cp->un.ord = sc->aria_mix[ARIAMIX_AUX_LVL].mute;
1422 error = 0;
1423 }
1424 break;
1425
1426 case ARIAMIX_TEL_MUTE:
1427 if (cp->type == AUDIO_MIXER_ENUM) {
1428 cp->un.ord = sc->aria_mix[ARIAMIX_TEL_LVL].mute;
1429 error = 0;
1430 }
1431 break;
1432
1433 case ARIAMIX_MASTER_LVL:
1434 if (cp->type == AUDIO_MIXER_VALUE) {
1435 cp->un.value.num_channels =
1436 sc->ariamix_master.num_channels;
1437 cp->un.value.level[0] = sc->ariamix_master.level[0];
1438 cp->un.value.level[1] = sc->ariamix_master.level[1];
1439 error = 0;
1440 }
1441 break;
1442
1443 case ARIAMIX_MASTER_TREBLE:
1444 if (cp->type == AUDIO_MIXER_VALUE) {
1445 cp->un.value.num_channels = 2;
1446 cp->un.value.level[0] = sc->ariamix_master.treble[0];
1447 cp->un.value.level[1] = sc->ariamix_master.treble[1];
1448 error = 0;
1449 }
1450 break;
1451
1452 case ARIAMIX_MASTER_BASS:
1453 if (cp->type == AUDIO_MIXER_VALUE) {
1454 cp->un.value.num_channels = 2;
1455 cp->un.value.level[0] = sc->ariamix_master.bass[0];
1456 cp->un.value.level[1] = sc->ariamix_master.bass[1];
1457 error = 0;
1458 }
1459 break;
1460
1461 case ARIAMIX_OUT_LVL:
1462 if (cp->type == AUDIO_MIXER_VALUE) {
1463 cp->un.value.num_channels = sc->sc_chans;
1464 cp->un.value.level[0] = sc->sc_gain[0];
1465 cp->un.value.level[1] = sc->sc_gain[1];
1466 error = 0;
1467 }
1468 break;
1469 case ARIAMIX_RECORD_SOURCE:
1470 if (cp->type == AUDIO_MIXER_ENUM) {
1471 cp->un.ord = sc->aria_mix_source;
1472 error = 0;
1473 }
1474 break;
1475
1476 default:
1477 return ENXIO;
1478 /* NOT REACHED */
1479 }
1480
1481 return(error);
1482 }
1483
1484 int
1485 aria_mixer_query_devinfo(addr, dip)
1486 void *addr;
1487 mixer_devinfo_t *dip;
1488 {
1489
1490 struct aria_softc *sc = addr;
1491
1492 DPRINTF(("aria_mixer_query_devinfo\n"));
1493
1494 /* This could be done better, no mixer still has some controls. */
1495 if (!(ARIA_MIXER & sc->sc_hardware))
1496 return ENXIO;
1497
1498 dip->prev = dip->next = AUDIO_MIXER_LAST;
1499
1500 switch(dip->index) {
1501 case ARIAMIX_MIC_LVL:
1502 dip->type = AUDIO_MIXER_VALUE;
1503 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1504 dip->next = ARIAMIX_MIC_MUTE;
1505 strcpy(dip->label.name, AudioNmicrophone);
1506 dip->un.v.num_channels = 2;
1507 strcpy(dip->un.v.units.name, AudioNvolume);
1508 break;
1509
1510 case ARIAMIX_LINE_IN_LVL:
1511 dip->type = AUDIO_MIXER_VALUE;
1512 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1513 dip->next = ARIAMIX_LINE_IN_MUTE;
1514 strcpy(dip->label.name, AudioNline);
1515 dip->un.v.num_channels = 2;
1516 strcpy(dip->un.v.units.name, AudioNvolume);
1517 break;
1518
1519 case ARIAMIX_CD_LVL:
1520 dip->type = AUDIO_MIXER_VALUE;
1521 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1522 dip->next = ARIAMIX_CD_MUTE;
1523 strcpy(dip->label.name, AudioNcd);
1524 dip->un.v.num_channels = 2;
1525 strcpy(dip->un.v.units.name, AudioNvolume);
1526 break;
1527
1528 case ARIAMIX_TEL_LVL:
1529 dip->type = AUDIO_MIXER_VALUE;
1530 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1531 dip->next = ARIAMIX_TEL_MUTE;
1532 strcpy(dip->label.name, "telephone");
1533 dip->un.v.num_channels = 1;
1534 strcpy(dip->un.v.units.name, AudioNvolume);
1535 break;
1536
1537 case ARIAMIX_DAC_LVL:
1538 dip->type = AUDIO_MIXER_VALUE;
1539 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1540 dip->next = ARIAMIX_DAC_MUTE;
1541 strcpy(dip->label.name, AudioNdac);
1542 dip->un.v.num_channels = 1;
1543 strcpy(dip->un.v.units.name, AudioNvolume);
1544 break;
1545
1546 case ARIAMIX_AUX_LVL:
1547 dip->type = AUDIO_MIXER_VALUE;
1548 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1549 dip->next = ARIAMIX_AUX_MUTE;
1550 strcpy(dip->label.name, AudioNoutput);
1551 dip->un.v.num_channels = 1;
1552 strcpy(dip->un.v.units.name, AudioNvolume);
1553 break;
1554
1555 case ARIAMIX_MIC_MUTE:
1556 dip->prev = ARIAMIX_MIC_LVL;
1557 goto mute;
1558
1559 case ARIAMIX_LINE_IN_MUTE:
1560 dip->prev = ARIAMIX_LINE_IN_LVL;
1561 goto mute;
1562
1563 case ARIAMIX_CD_MUTE:
1564 dip->prev = ARIAMIX_CD_LVL;
1565 goto mute;
1566
1567 case ARIAMIX_DAC_MUTE:
1568 dip->prev = ARIAMIX_DAC_LVL;
1569 goto mute;
1570
1571 case ARIAMIX_AUX_MUTE:
1572 dip->prev = ARIAMIX_AUX_LVL;
1573 goto mute;
1574
1575 case ARIAMIX_TEL_MUTE:
1576 dip->prev = ARIAMIX_TEL_LVL;
1577 goto mute;
1578
1579 mute:
1580 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1581 dip->type = AUDIO_MIXER_ENUM;
1582 strcpy(dip->label.name, AudioNmute);
1583 dip->un.e.num_mem = 2;
1584 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1585 dip->un.e.member[0].ord = 0;
1586 strcpy(dip->un.e.member[1].label.name, AudioNon);
1587 dip->un.e.member[1].ord = 1;
1588 break;
1589
1590 case ARIAMIX_MASTER_LVL:
1591 dip->type = AUDIO_MIXER_VALUE;
1592 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1593 dip->next = AUDIO_MIXER_LAST;
1594 strcpy(dip->label.name, AudioNvolume);
1595 dip->un.v.num_channels = 2;
1596 strcpy(dip->un.v.units.name, AudioNvolume);
1597 break;
1598
1599 case ARIAMIX_MASTER_TREBLE:
1600 dip->type = AUDIO_MIXER_VALUE;
1601 dip->mixer_class = ARIAMIX_EQ_CLASS;
1602 strcpy(dip->label.name, AudioNtreble);
1603 dip->un.v.num_channels = 2;
1604 strcpy(dip->un.v.units.name, AudioNtreble);
1605 break;
1606
1607 case ARIAMIX_MASTER_BASS:
1608 dip->type = AUDIO_MIXER_VALUE;
1609 dip->mixer_class = ARIAMIX_EQ_CLASS;
1610 strcpy(dip->label.name, AudioNbass);
1611 dip->un.v.num_channels = 2;
1612 strcpy(dip->un.v.units.name, AudioNbass);
1613 break;
1614
1615 case ARIAMIX_OUT_LVL:
1616 dip->type = AUDIO_MIXER_VALUE;
1617 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1618 strcpy(dip->label.name, AudioNoutput);
1619 dip->un.v.num_channels = 2;
1620 strcpy(dip->un.v.units.name, AudioNvolume);
1621 break;
1622
1623 case ARIAMIX_RECORD_SOURCE:
1624 dip->mixer_class = ARIAMIX_RECORD_CLASS;
1625 dip->type = AUDIO_MIXER_ENUM;
1626 strcpy(dip->label.name, AudioNsource);
1627 dip->un.e.num_mem = 6;
1628 strcpy(dip->un.e.member[0].label.name, AudioNoutput);
1629 dip->un.e.member[0].ord = ARIAMIX_AUX_LVL;
1630 strcpy(dip->un.e.member[1].label.name, AudioNmicrophone);
1631 dip->un.e.member[1].ord = ARIAMIX_MIC_LVL;
1632 strcpy(dip->un.e.member[2].label.name, AudioNdac);
1633 dip->un.e.member[2].ord = ARIAMIX_DAC_LVL;
1634 strcpy(dip->un.e.member[3].label.name, AudioNline);
1635 dip->un.e.member[3].ord = ARIAMIX_LINE_IN_LVL;
1636 strcpy(dip->un.e.member[4].label.name, AudioNcd);
1637 dip->un.e.member[4].ord = ARIAMIX_CD_LVL;
1638 strcpy(dip->un.e.member[5].label.name, "telephone");
1639 dip->un.e.member[5].ord = ARIAMIX_TEL_LVL;
1640 break;
1641
1642 case ARIAMIX_INPUT_CLASS:
1643 dip->type = AUDIO_MIXER_CLASS;
1644 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1645 strcpy(dip->label.name, AudioCinputs);
1646 break;
1647
1648 case ARIAMIX_OUTPUT_CLASS:
1649 dip->type = AUDIO_MIXER_CLASS;
1650 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1651 strcpy(dip->label.name, AudioCoutputs);
1652 break;
1653
1654 case ARIAMIX_RECORD_CLASS:
1655 dip->type = AUDIO_MIXER_CLASS;
1656 dip->mixer_class = ARIAMIX_RECORD_CLASS;
1657 strcpy(dip->label.name, AudioCrecord);
1658 break;
1659
1660 case ARIAMIX_EQ_CLASS:
1661 dip->type = AUDIO_MIXER_CLASS;
1662 dip->mixer_class = ARIAMIX_EQ_CLASS;
1663 strcpy(dip->label.name, AudioCequalization);
1664 break;
1665
1666 default:
1667 return ENXIO;
1668 /*NOTREACHED*/
1669 }
1670 return 0;
1671 }
1672