1 /* $NetBSD: aica.c,v 1.10 2005/12/11 12:17:06 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2003 SHIMIZU Ryo <ryo@misakimix.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <sys/cdefs.h> 32 __KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.10 2005/12/11 12:17:06 christos Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/proc.h> 38 #include <sys/audioio.h> 39 40 #include <dev/audio_if.h> 41 #include <dev/mulaw.h> 42 #include <dev/auconv.h> 43 44 #include <machine/bus.h> 45 #include <machine/sysasicvar.h> 46 47 #include <dreamcast/dev/g2/g2busvar.h> 48 #include <dreamcast/dev/g2/aicavar.h> 49 #include <dreamcast/dev/microcode/aica_armcode.h> 50 51 #define AICA_REG_ADDR 0x00700000 52 #define AICA_RAM_START 0x00800000 53 #define AICA_RAM_SIZE 0x00200000 54 #define AICA_NCHAN 64 55 #define AICA_TIMEOUT 0x1800 56 57 struct aica_softc { 58 struct device sc_dev; /* base device */ 59 bus_space_tag_t sc_memt; 60 bus_space_handle_t sc_aica_regh; 61 bus_space_handle_t sc_aica_memh; 62 63 /* audio property */ 64 int sc_open; 65 int sc_encodings; 66 int sc_precision; 67 int sc_channels; 68 int sc_rate; 69 void (*sc_intr)(void *); 70 void *sc_intr_arg; 71 72 int sc_output_master; 73 int sc_output_gain[2]; 74 #define AICA_VOLUME_LEFT 0 75 #define AICA_VOLUME_RIGHT 1 76 77 /* work for output */ 78 void *sc_buffer; 79 void *sc_buffer_start; 80 void *sc_buffer_end; 81 int sc_blksize; 82 int sc_nextfill; 83 }; 84 85 const struct { 86 const char *name; 87 int encoding; 88 int precision; 89 } aica_encodings[] = { 90 {AudioEadpcm, AUDIO_ENCODING_ADPCM, 4}, 91 {AudioEslinear, AUDIO_ENCODING_SLINEAR, 8}, 92 {AudioEulinear, AUDIO_ENCODING_ULINEAR, 8}, 93 {AudioEmulaw, AUDIO_ENCODING_ULAW, 8}, 94 {AudioEalaw, AUDIO_ENCODING_ALAW, 8}, 95 {AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE, 16}, 96 {AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE, 16}, 97 {AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE, 16}, 98 {AudioEulinear_le, AUDIO_ENCODING_ULINEAR_LE, 16}, 99 }; 100 101 #define AICA_NFORMATS 5 102 static const struct audio_format aica_formats[AICA_NFORMATS] = { 103 {NULL, AUMODE_PLAY, AUDIO_ENCODING_ADPCM, 4, 4, 104 1, AUFMT_MONAURAL, 0, {1, 65536}}, 105 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16, 106 1, AUFMT_MONAURAL, 0, {1, 65536}}, 107 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16, 108 2, AUFMT_STEREO, 0, {1, 65536}}, 109 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 8, 8, 110 1, AUFMT_MONAURAL, 0, {1, 65536}}, 111 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 8, 8, 112 2, AUFMT_STEREO, 0, {1, 65536}}, 113 }; 114 115 int aica_match(struct device *, struct cfdata *, void *); 116 void aica_attach(struct device *, struct device *, void *); 117 int aica_print(void *, const char *); 118 119 CFATTACH_DECL(aica, sizeof(struct aica_softc), aica_match, aica_attach, 120 NULL, NULL); 121 122 const struct audio_device aica_device = { 123 "Dreamcast Sound", 124 "", 125 "aica" 126 }; 127 128 __inline static void aica_g2fifo_wait(void); 129 void aica_enable(struct aica_softc *); 130 void aica_disable(struct aica_softc *); 131 void aica_memwrite(struct aica_softc *, bus_size_t, uint32_t *, int); 132 void aica_ch2p16write(struct aica_softc *, bus_size_t, uint16_t *, int); 133 void aica_ch2p8write(struct aica_softc *, bus_size_t, uint8_t *, int); 134 void aica_command(struct aica_softc *, uint32_t); 135 void aica_sendparam(struct aica_softc *, uint32_t, int, int); 136 void aica_play(struct aica_softc *, int, int, int, int); 137 void aica_fillbuffer(struct aica_softc *); 138 139 /* intr */ 140 int aica_intr(void *); 141 142 /* for audio */ 143 int aica_open(void *, int); 144 void aica_close(void *); 145 int aica_query_encoding(void *, struct audio_encoding *); 146 int aica_set_params(void *, int, int, audio_params_t *, 147 audio_params_t *, stream_filter_list_t *, stream_filter_list_t *); 148 int aica_round_blocksize(void *, int, int, const audio_params_t *); 149 size_t aica_round_buffersize(void *, int, size_t); 150 int aica_trigger_output(void *, void *, void *, int, void (*)(void *), void *, 151 const audio_params_t *); 152 int aica_trigger_input(void *, void *, void *, int, void (*)(void *), void *, 153 const audio_params_t *); 154 int aica_halt_output(void *); 155 int aica_halt_input(void *); 156 int aica_getdev(void *, struct audio_device *); 157 int aica_set_port(void *, mixer_ctrl_t *); 158 int aica_get_port(void *, mixer_ctrl_t *); 159 int aica_query_devinfo(void *, mixer_devinfo_t *); 160 void aica_encode(int, int, int, int, u_char *, u_short **); 161 int aica_get_props(void *); 162 163 const struct audio_hw_if aica_hw_if = { 164 aica_open, 165 aica_close, 166 NULL, /* aica_drain */ 167 aica_query_encoding, 168 aica_set_params, 169 aica_round_blocksize, 170 NULL, /* aica_commit_setting */ 171 NULL, /* aica_init_output */ 172 NULL, /* aica_init_input */ 173 NULL, /* aica_start_output */ 174 NULL, /* aica_start_input */ 175 aica_halt_output, 176 aica_halt_input, 177 NULL, /* aica_speaker_ctl */ 178 aica_getdev, 179 NULL, /* aica_setfd */ 180 aica_set_port, 181 aica_get_port, 182 aica_query_devinfo, 183 NULL, /* aica_allocm */ 184 NULL, /* aica_freem */ 185 186 aica_round_buffersize, /* aica_round_buffersize */ 187 188 NULL, /* aica_mappage */ 189 aica_get_props, 190 aica_trigger_output, 191 aica_trigger_input, 192 NULL, /* aica_dev_ioctl */ 193 }; 194 195 int 196 aica_match(struct device *parent, struct cfdata *cf, void *aux) 197 { 198 static int aica_matched = 0; 199 200 if (aica_matched) 201 return 0; 202 203 aica_matched = 1; 204 return 1; 205 } 206 207 void 208 aica_attach(struct device *parent, struct device *self, void *aux) 209 { 210 struct aica_softc *sc; 211 struct g2bus_attach_args *ga; 212 int i; 213 214 sc = (struct aica_softc *)self; 215 ga = aux; 216 sc->sc_memt = ga->ga_memt; 217 218 if (bus_space_map(sc->sc_memt, AICA_REG_ADDR, 0x3000, 0, 219 &sc->sc_aica_regh) != 0) { 220 printf(": can't map AICA register space\n"); 221 return; 222 } 223 224 if (bus_space_map(sc->sc_memt, AICA_RAM_START, AICA_RAM_SIZE, 0, 225 &sc->sc_aica_memh) != 0) { 226 printf(": can't map AICA memory space\n"); 227 return; 228 } 229 230 printf(": ARM7 Sound Processing Unit\n"); 231 232 aica_disable(sc); 233 234 for (i = 0; i < AICA_NCHAN; i++) 235 bus_space_write_4(sc->sc_memt,sc->sc_aica_regh, i << 7, 236 ((bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, i << 7) 237 & ~0x4000) | 0x8000)); 238 239 /* load microcode, and clear memory */ 240 bus_space_set_region_4(sc->sc_memt, sc->sc_aica_memh, 241 0, 0, AICA_RAM_SIZE); 242 243 aica_memwrite(sc, 0, aica_armcode, sizeof(aica_armcode)); 244 245 aica_enable(sc); 246 247 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, 248 sysasic_intr_string(IPL_BIO)); 249 sysasic_intr_establish(SYSASIC_EVENT_AICA, IPL_BIO, aica_intr, sc); 250 251 audio_attach_mi(&aica_hw_if, sc, &sc->sc_dev); 252 253 /* init parameters */ 254 sc->sc_output_master = 255; 255 sc->sc_output_gain[AICA_VOLUME_LEFT] = 255; 256 sc->sc_output_gain[AICA_VOLUME_RIGHT] = 255; 257 } 258 259 void 260 aica_enable(struct aica_softc *sc) 261 { 262 263 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28a8, 24); 264 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00, 265 bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) & ~1); 266 } 267 268 void 269 aica_disable(struct aica_softc *sc) 270 { 271 272 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00, 273 bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) | 1); 274 } 275 276 inline static void 277 aica_g2fifo_wait(void) 278 { 279 int i; 280 281 i = AICA_TIMEOUT; 282 while (--i > 0) 283 if ((*(volatile uint32_t *)0xa05f688c) & 0x11) 284 break; 285 } 286 287 void 288 aica_memwrite(struct aica_softc *sc, bus_size_t offset, uint32_t *src, int len) 289 { 290 int n; 291 292 KASSERT((offset & 3) == 0); 293 n = (len + 3) / 4; /* uint32_t * n (aligned) */ 294 295 aica_g2fifo_wait(); 296 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh, 297 offset, src, n); 298 } 299 300 void 301 aica_ch2p16write(struct aica_softc *sc, bus_size_t offset, uint16_t *src, 302 int len) 303 { 304 union { 305 uint32_t w[8]; 306 uint16_t s[16]; 307 } buf; 308 uint16_t *p; 309 int i; 310 311 KASSERT((offset & 3) == 0); 312 313 while (len >= 32) { 314 p = buf.s; 315 *p++ = *src++; src++; 316 *p++ = *src++; src++; 317 *p++ = *src++; src++; 318 *p++ = *src++; src++; 319 *p++ = *src++; src++; 320 *p++ = *src++; src++; 321 *p++ = *src++; src++; 322 *p++ = *src++; src++; 323 *p++ = *src++; src++; 324 *p++ = *src++; src++; 325 *p++ = *src++; src++; 326 *p++ = *src++; src++; 327 *p++ = *src++; src++; 328 *p++ = *src++; src++; 329 *p++ = *src++; src++; 330 *p++ = *src++; src++; 331 332 aica_g2fifo_wait(); 333 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh, 334 offset, buf.w , 32 / 4); 335 336 offset += sizeof(uint16_t) * 16; 337 len -= 32; 338 } 339 340 if (len / 2 > 0) { 341 p = buf.s; 342 for (i = 0; i < len / 2; i++) { 343 *p++ = *src++; src++; 344 } 345 346 aica_g2fifo_wait(); 347 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh, 348 offset, buf.w, len / 4); 349 } 350 } 351 352 void 353 aica_ch2p8write(struct aica_softc *sc, bus_size_t offset, uint8_t *src, 354 int len) 355 { 356 uint32_t buf[8]; 357 uint8_t *p; 358 int i; 359 360 KASSERT((offset & 3) == 0); 361 while (len >= 32) { 362 p = (uint8_t *)buf; 363 364 *p++ = *src++; src++; 365 *p++ = *src++; src++; 366 *p++ = *src++; src++; 367 *p++ = *src++; src++; 368 *p++ = *src++; src++; 369 *p++ = *src++; src++; 370 *p++ = *src++; src++; 371 *p++ = *src++; src++; 372 *p++ = *src++; src++; 373 *p++ = *src++; src++; 374 *p++ = *src++; src++; 375 *p++ = *src++; src++; 376 *p++ = *src++; src++; 377 *p++ = *src++; src++; 378 *p++ = *src++; src++; 379 *p++ = *src++; src++; 380 *p++ = *src++; src++; 381 *p++ = *src++; src++; 382 *p++ = *src++; src++; 383 *p++ = *src++; src++; 384 *p++ = *src++; src++; 385 *p++ = *src++; src++; 386 *p++ = *src++; src++; 387 *p++ = *src++; src++; 388 *p++ = *src++; src++; 389 *p++ = *src++; src++; 390 *p++ = *src++; src++; 391 *p++ = *src++; src++; 392 *p++ = *src++; src++; 393 *p++ = *src++; src++; 394 *p++ = *src++; src++; 395 *p++ = *src++; src++; 396 397 aica_g2fifo_wait(); 398 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh, 399 offset, buf, 32 / 4); 400 401 offset += 32; 402 len -= 32; 403 } 404 405 if (len) { 406 p = (uint8_t *)buf; 407 for (i = 0; i < len; i++) 408 *p++ = *src++; src++; 409 410 aica_g2fifo_wait(); 411 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh, 412 offset, buf, len / 4); 413 } 414 } 415 416 int 417 aica_open(void *addr, int flags) 418 { 419 struct aica_softc *sc; 420 421 sc = addr; 422 if (sc->sc_open) 423 return EBUSY; 424 425 sc->sc_intr = NULL; 426 sc->sc_open = 1; 427 428 return 0; 429 } 430 431 void 432 aica_close(void *addr) 433 { 434 struct aica_softc *sc; 435 436 sc = addr; 437 sc->sc_open = 0; 438 sc->sc_intr = NULL; 439 } 440 441 int 442 aica_query_encoding(void *addr, struct audio_encoding *fp) 443 { 444 if (fp->index >= sizeof(aica_encodings) / sizeof(aica_encodings[0])) 445 return EINVAL; 446 447 strcpy(fp->name, aica_encodings[fp->index].name); 448 fp->encoding = aica_encodings[fp->index].encoding; 449 fp->precision = aica_encodings[fp->index].precision; 450 fp->flags = 0; 451 452 return 0; 453 } 454 455 int 456 aica_set_params(void *addr, int setmode, int usemode, 457 audio_params_t *play, audio_params_t *rec, 458 stream_filter_list_t *pfil, stream_filter_list_t *rfil) 459 { 460 struct aica_softc *sc; 461 const audio_params_t *hw; 462 int i; 463 464 i = auconv_set_converter(aica_formats, AICA_NFORMATS, 465 AUMODE_PLAY, play, FALSE, pfil); 466 if (i < 0) 467 return EINVAL; 468 hw = pfil->req_size > 0 ? &pfil->filters[0].param : play; 469 sc = addr; 470 sc->sc_precision = hw->precision; 471 sc->sc_channels = hw->channels; 472 sc->sc_rate = hw->sample_rate; 473 sc->sc_encodings = hw->encoding; 474 return 0; 475 } 476 477 int 478 aica_round_blocksize(void *addr, int blk, int mode, const audio_params_t *param) 479 { 480 struct aica_softc *sc; 481 482 sc = addr; 483 switch (sc->sc_precision) { 484 case 4: 485 if (sc->sc_channels == 1) 486 return AICA_DMABUF_SIZE / 4; 487 else 488 return AICA_DMABUF_SIZE / 2; 489 break; 490 case 8: 491 if (sc->sc_channels == 1) 492 return AICA_DMABUF_SIZE / 2; 493 else 494 return AICA_DMABUF_SIZE; 495 break; 496 case 16: 497 if (sc->sc_channels == 1) 498 return AICA_DMABUF_SIZE; 499 else 500 return AICA_DMABUF_SIZE * 2; 501 break; 502 default: 503 break; 504 } 505 506 return AICA_DMABUF_SIZE / 4; 507 } 508 509 size_t 510 aica_round_buffersize(void *addr, int dir, size_t bufsize) 511 { 512 513 if (dir == AUMODE_PLAY) 514 return 65536; 515 516 return 512; /* XXX: AUMINBUF */ 517 } 518 519 void 520 aica_command(struct aica_softc *sc, uint32_t command) 521 { 522 523 bus_space_write_4(sc->sc_memt, sc->sc_aica_memh, 524 AICA_ARM_CMD_COMMAND, command); 525 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, AICA_ARM_CMD_SERIAL, 526 bus_space_read_4(sc->sc_memt, sc->sc_aica_memh, 527 AICA_ARM_CMD_SERIAL) + 1); 528 } 529 530 void 531 aica_sendparam(struct aica_softc *sc, uint32_t command, 532 int32_t lparam, int32_t rparam) 533 { 534 535 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 536 AICA_ARM_CMD_LPARAM, lparam); 537 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 538 AICA_ARM_CMD_RPARAM, rparam); 539 540 aica_command(sc, command); 541 } 542 543 void 544 aica_play(struct aica_softc *sc, int blksize, int channel, int rate, int prec) 545 { 546 547 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 548 AICA_ARM_CMD_BLOCKSIZE, blksize); 549 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 550 AICA_ARM_CMD_CHANNEL, channel); 551 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 552 AICA_ARM_CMD_RATE, rate); 553 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, 554 AICA_ARM_CMD_PRECISION, prec); 555 556 aica_command(sc, AICA_COMMAND_PLAY); 557 } 558 559 void 560 aica_fillbuffer(struct aica_softc *sc) 561 { 562 563 if (sc->sc_channels == 2) { 564 if (sc->sc_precision == 16) { 565 aica_ch2p16write(sc, 566 AICA_DMABUF_LEFT + sc->sc_nextfill, 567 (uint16_t *)sc->sc_buffer + 0, sc->sc_blksize / 2); 568 aica_ch2p16write(sc, 569 AICA_DMABUF_RIGHT + sc->sc_nextfill, 570 (uint16_t *)sc->sc_buffer + 1, sc->sc_blksize / 2); 571 } else if (sc->sc_precision == 8) { 572 aica_ch2p8write(sc, AICA_DMABUF_LEFT + sc->sc_nextfill, 573 (uint8_t *)sc->sc_buffer + 0, sc->sc_blksize / 2); 574 aica_ch2p8write(sc, AICA_DMABUF_RIGHT + sc->sc_nextfill, 575 (uint8_t *)sc->sc_buffer + 1, sc->sc_blksize / 2); 576 } 577 } else { 578 aica_memwrite(sc, AICA_DMABUF_MONO + sc->sc_nextfill, 579 sc->sc_buffer, sc->sc_blksize); 580 } 581 582 (int8_t *)sc->sc_buffer += sc->sc_blksize; 583 if (sc->sc_buffer >= sc->sc_buffer_end) 584 sc->sc_buffer = sc->sc_buffer_start; 585 586 sc->sc_nextfill ^= sc->sc_blksize / sc->sc_channels; 587 } 588 589 int 590 aica_intr(void *arg) 591 { 592 struct aica_softc *sc; 593 594 sc = arg; 595 aica_fillbuffer(sc); 596 597 /* call audio interrupt handler (audio_pint()) */ 598 if (sc->sc_open && sc->sc_intr != NULL) { 599 (*(sc->sc_intr))(sc->sc_intr_arg); 600 } 601 602 /* clear SPU interrupt */ 603 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28bc, 0x20); 604 return 1; 605 } 606 607 int 608 aica_trigger_output(void *addr, void *start, void *end, int blksize, 609 void (*intr)(void *), void *arg, const audio_params_t *param) 610 { 611 struct aica_softc *sc; 612 613 sc = addr; 614 aica_command(sc, AICA_COMMAND_INIT); 615 tsleep(aica_trigger_output, PWAIT, "aicawait", hz / 20); 616 617 sc->sc_buffer_start = sc->sc_buffer = start; 618 sc->sc_buffer_end = end; 619 sc->sc_blksize = blksize; 620 sc->sc_nextfill = 0; 621 622 sc->sc_intr = intr; 623 sc->sc_intr_arg = arg; 624 625 /* fill buffers in advance */ 626 aica_intr(sc); 627 aica_intr(sc); 628 629 /* ...and start playing */ 630 aica_play(sc, blksize / sc->sc_channels, sc->sc_channels, sc->sc_rate, 631 sc->sc_precision); 632 633 return 0; 634 } 635 636 int 637 aica_trigger_input(void *addr, void *start, void *end, int blksize, 638 void (*intr)(void *), void *arg, const audio_params_t *param) 639 { 640 641 return ENODEV; 642 } 643 644 int 645 aica_halt_output(void *addr) 646 { 647 struct aica_softc *sc; 648 649 sc = addr; 650 aica_command(sc, AICA_COMMAND_STOP); 651 return 0; 652 } 653 654 int 655 aica_halt_input(void *addr) 656 { 657 658 return ENODEV; 659 } 660 661 int 662 aica_getdev(void *addr, struct audio_device *ret) 663 { 664 665 *ret = aica_device; 666 return 0; 667 } 668 669 int 670 aica_set_port(void *addr, mixer_ctrl_t *mc) 671 { 672 struct aica_softc *sc; 673 674 sc = addr; 675 switch (mc->dev) { 676 case AICA_MASTER_VOL: 677 sc->sc_output_master = 678 mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] & 0xff; 679 aica_sendparam(sc, AICA_COMMAND_MVOL, 680 sc->sc_output_master, sc->sc_output_master); 681 break; 682 case AICA_OUTPUT_GAIN: 683 sc->sc_output_gain[AICA_VOLUME_LEFT] = 684 mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] & 0xff; 685 sc->sc_output_gain[AICA_VOLUME_RIGHT] = 686 mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & 0xff; 687 aica_sendparam(sc, AICA_COMMAND_VOL, 688 sc->sc_output_gain[AICA_VOLUME_LEFT], 689 sc->sc_output_gain[AICA_VOLUME_RIGHT]); 690 break; 691 default: 692 return EINVAL; 693 } 694 695 return 0; 696 } 697 698 int 699 aica_get_port(void *addr, mixer_ctrl_t *mc) 700 { 701 struct aica_softc *sc; 702 703 sc = addr; 704 switch (mc->dev) { 705 case AICA_MASTER_VOL: 706 if (mc->un.value.num_channels != 1) 707 return EINVAL; 708 mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = 709 L16TO256(L256TO16(sc->sc_output_master)); 710 break; 711 case AICA_OUTPUT_GAIN: 712 mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 713 sc->sc_output_gain[AICA_VOLUME_LEFT]; 714 mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 715 sc->sc_output_gain[AICA_VOLUME_RIGHT]; 716 break; 717 default: 718 return EINVAL; 719 } 720 return 0; 721 } 722 723 int 724 aica_query_devinfo(void *addr, mixer_devinfo_t *md) 725 { 726 727 switch (md->index) { 728 case AICA_MASTER_VOL: 729 md->type = AUDIO_MIXER_VALUE; 730 md->mixer_class = AICA_OUTPUT_CLASS; 731 md->prev = md->next = AUDIO_MIXER_LAST; 732 strcpy(md->label.name, AudioNmaster); 733 md->un.v.num_channels = 1; 734 strcpy(md->un.v.units.name, AudioNvolume); 735 return 0; 736 case AICA_OUTPUT_GAIN: 737 md->type = AUDIO_MIXER_VALUE; 738 md->mixer_class = AICA_OUTPUT_CLASS; 739 md->prev = md->next = AUDIO_MIXER_LAST; 740 strcpy(md->label.name, AudioNoutput); 741 md->un.v.num_channels = 2; 742 strcpy(md->label.name, AudioNvolume); 743 return 0; 744 case AICA_OUTPUT_CLASS: 745 md->type = AUDIO_MIXER_CLASS; 746 md->mixer_class = AICA_OUTPUT_CLASS; 747 md->next = md->prev = AUDIO_MIXER_LAST; 748 strcpy(md->label.name, AudioCoutputs); 749 return 0; 750 } 751 752 return ENXIO; 753 } 754 755 int 756 aica_get_props(void *addr) 757 { 758 759 return 0; 760 } 761