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