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