1 /* $NetBSD: eso.c,v 1.42 2006/04/14 19:03:32 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1999, 2000, 2004 Klaus J. Klein 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 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 /* 32 * ESS Technology Inc. Solo-1 PCI AudioDrive (ES1938/1946) device driver. 33 */ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: eso.c,v 1.42 2006/04/14 19:03:32 christos Exp $"); 37 38 #include "mpu.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/kernel.h> 43 #include <sys/malloc.h> 44 #include <sys/device.h> 45 #include <sys/proc.h> 46 47 #include <dev/pci/pcidevs.h> 48 #include <dev/pci/pcivar.h> 49 50 #include <sys/audioio.h> 51 #include <dev/audio_if.h> 52 #include <dev/midi_if.h> 53 54 #include <dev/mulaw.h> 55 #include <dev/auconv.h> 56 57 #include <dev/ic/mpuvar.h> 58 #include <dev/ic/i8237reg.h> 59 #include <dev/pci/esoreg.h> 60 #include <dev/pci/esovar.h> 61 62 #include <machine/bus.h> 63 #include <machine/intr.h> 64 65 /* 66 * XXX Work around the 24-bit implementation limit of the Audio 1 DMA 67 * XXX engine by allocating through the ISA DMA tag. 68 */ 69 #if defined(amd64) || defined(i386) 70 #include "isa.h" 71 #if NISA > 0 72 #include <dev/isa/isavar.h> 73 #endif 74 #endif 75 76 #if defined(AUDIO_DEBUG) || defined(DEBUG) 77 #define DPRINTF(x) printf x 78 #else 79 #define DPRINTF(x) 80 #endif 81 82 struct eso_dma { 83 bus_dma_tag_t ed_dmat; 84 bus_dmamap_t ed_map; 85 caddr_t ed_addr; 86 bus_dma_segment_t ed_segs[1]; 87 int ed_nsegs; 88 size_t ed_size; 89 struct eso_dma * ed_next; 90 }; 91 92 #define KVADDR(dma) ((void *)(dma)->ed_addr) 93 #define DMAADDR(dma) ((dma)->ed_map->dm_segs[0].ds_addr) 94 95 /* Autoconfiguration interface */ 96 static int eso_match(struct device *, struct cfdata *, void *); 97 static void eso_attach(struct device *, struct device *, void *); 98 static void eso_defer(struct device *); 99 static int eso_print(void *, const char *); 100 101 CFATTACH_DECL(eso, sizeof (struct eso_softc), 102 eso_match, eso_attach, NULL, NULL); 103 104 /* PCI interface */ 105 static int eso_intr(void *); 106 107 /* MI audio layer interface */ 108 static int eso_query_encoding(void *, struct audio_encoding *); 109 static int eso_set_params(void *, int, int, audio_params_t *, 110 audio_params_t *, stream_filter_list_t *, 111 stream_filter_list_t *); 112 static int eso_round_blocksize(void *, int, int, const audio_params_t *); 113 static int eso_halt_output(void *); 114 static int eso_halt_input(void *); 115 static int eso_getdev(void *, struct audio_device *); 116 static int eso_set_port(void *, mixer_ctrl_t *); 117 static int eso_get_port(void *, mixer_ctrl_t *); 118 static int eso_query_devinfo(void *, mixer_devinfo_t *); 119 static void * eso_allocm(void *, int, size_t, struct malloc_type *, int); 120 static void eso_freem(void *, void *, struct malloc_type *); 121 static size_t eso_round_buffersize(void *, int, size_t); 122 static paddr_t eso_mappage(void *, void *, off_t, int); 123 static int eso_get_props(void *); 124 static int eso_trigger_output(void *, void *, void *, int, 125 void (*)(void *), void *, const audio_params_t *); 126 static int eso_trigger_input(void *, void *, void *, int, 127 void (*)(void *), void *, const audio_params_t *); 128 129 static const struct audio_hw_if eso_hw_if = { 130 NULL, /* open */ 131 NULL, /* close */ 132 NULL, /* drain */ 133 eso_query_encoding, 134 eso_set_params, 135 eso_round_blocksize, 136 NULL, /* commit_settings */ 137 NULL, /* init_output */ 138 NULL, /* init_input */ 139 NULL, /* start_output */ 140 NULL, /* start_input */ 141 eso_halt_output, 142 eso_halt_input, 143 NULL, /* speaker_ctl */ 144 eso_getdev, 145 NULL, /* setfd */ 146 eso_set_port, 147 eso_get_port, 148 eso_query_devinfo, 149 eso_allocm, 150 eso_freem, 151 eso_round_buffersize, 152 eso_mappage, 153 eso_get_props, 154 eso_trigger_output, 155 eso_trigger_input, 156 NULL, /* dev_ioctl */ 157 }; 158 159 static const char * const eso_rev2model[] = { 160 "ES1938", 161 "ES1946", 162 "ES1946 Revision E" 163 }; 164 165 #define ESO_NFORMATS 8 166 static const struct audio_format eso_formats[ESO_NFORMATS] = { 167 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16, 168 2, AUFMT_STEREO, 0, {ESO_MINRATE, ESO_MAXRATE}}, 169 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16, 170 1, AUFMT_MONAURAL, 0, {ESO_MINRATE, ESO_MAXRATE}}, 171 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 16, 16, 172 2, AUFMT_STEREO, 0, {ESO_MINRATE, ESO_MAXRATE}}, 173 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 16, 16, 174 1, AUFMT_MONAURAL, 0, {ESO_MINRATE, ESO_MAXRATE}}, 175 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 8, 8, 176 2, AUFMT_STEREO, 0, {ESO_MINRATE, ESO_MAXRATE}}, 177 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 8, 8, 178 1, AUFMT_MONAURAL, 0, {ESO_MINRATE, ESO_MAXRATE}}, 179 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8, 180 2, AUFMT_STEREO, 0, {ESO_MINRATE, ESO_MAXRATE}}, 181 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8, 182 1, AUFMT_MONAURAL, 0, {ESO_MINRATE, ESO_MAXRATE}} 183 }; 184 185 186 /* 187 * Utility routines 188 */ 189 /* Register access etc. */ 190 static uint8_t eso_read_ctlreg(struct eso_softc *, uint8_t); 191 static uint8_t eso_read_mixreg(struct eso_softc *, uint8_t); 192 static uint8_t eso_read_rdr(struct eso_softc *); 193 static void eso_reload_master_vol(struct eso_softc *); 194 static int eso_reset(struct eso_softc *); 195 static void eso_set_gain(struct eso_softc *, unsigned int); 196 static int eso_set_recsrc(struct eso_softc *, unsigned int); 197 static int eso_set_monooutsrc(struct eso_softc *, unsigned int); 198 static int eso_set_monoinbypass(struct eso_softc *, unsigned int); 199 static int eso_set_preamp(struct eso_softc *, unsigned int); 200 static void eso_write_cmd(struct eso_softc *, uint8_t); 201 static void eso_write_ctlreg(struct eso_softc *, uint8_t, uint8_t); 202 static void eso_write_mixreg(struct eso_softc *, uint8_t, uint8_t); 203 /* DMA memory allocation */ 204 static int eso_allocmem(struct eso_softc *, size_t, size_t, size_t, 205 int, int, struct eso_dma *); 206 static void eso_freemem(struct eso_dma *); 207 208 209 static int 210 eso_match(struct device *parent, struct cfdata *match, void *aux) 211 { 212 struct pci_attach_args *pa; 213 214 pa = aux; 215 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ESSTECH && 216 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ESSTECH_SOLO1) 217 return 1; 218 219 return 0; 220 } 221 222 static void 223 eso_attach(struct device *parent, struct device *self, void *aux) 224 { 225 struct eso_softc *sc; 226 struct pci_attach_args *pa; 227 struct audio_attach_args aa; 228 pci_intr_handle_t ih; 229 bus_addr_t vcbase; 230 const char *intrstring; 231 int idx; 232 uint8_t a2mode, mvctl; 233 234 sc = (struct eso_softc *)self; 235 pa = aux; 236 aprint_naive(": Audio controller\n"); 237 238 sc->sc_revision = PCI_REVISION(pa->pa_class); 239 240 aprint_normal(": ESS Solo-1 PCI AudioDrive "); 241 if (sc->sc_revision < 242 sizeof (eso_rev2model) / sizeof (eso_rev2model[0])) 243 aprint_normal("%s\n", eso_rev2model[sc->sc_revision]); 244 else 245 aprint_normal("(unknown rev. 0x%02x)\n", sc->sc_revision); 246 247 /* Map I/O registers. */ 248 if (pci_mapreg_map(pa, ESO_PCI_BAR_IO, PCI_MAPREG_TYPE_IO, 0, 249 &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) { 250 aprint_error("%s: can't map I/O space\n", sc->sc_dev.dv_xname); 251 return; 252 } 253 if (pci_mapreg_map(pa, ESO_PCI_BAR_SB, PCI_MAPREG_TYPE_IO, 0, 254 &sc->sc_sb_iot, &sc->sc_sb_ioh, NULL, NULL)) { 255 aprint_error("%s: can't map SB I/O space\n", 256 sc->sc_dev.dv_xname); 257 return; 258 } 259 if (pci_mapreg_map(pa, ESO_PCI_BAR_VC, PCI_MAPREG_TYPE_IO, 0, 260 &sc->sc_dmac_iot, &sc->sc_dmac_ioh, &vcbase, &sc->sc_vcsize)) { 261 aprint_error("%s: can't map VC I/O space\n", 262 sc->sc_dev.dv_xname); 263 /* Don't bail out yet: we can map it later, see below. */ 264 vcbase = 0; 265 sc->sc_vcsize = 0x10; /* From the data sheet. */ 266 } 267 if (pci_mapreg_map(pa, ESO_PCI_BAR_MPU, PCI_MAPREG_TYPE_IO, 0, 268 &sc->sc_mpu_iot, &sc->sc_mpu_ioh, NULL, NULL)) { 269 aprint_error("%s: can't map MPU I/O space\n", 270 sc->sc_dev.dv_xname); 271 return; 272 } 273 if (pci_mapreg_map(pa, ESO_PCI_BAR_GAME, PCI_MAPREG_TYPE_IO, 0, 274 &sc->sc_game_iot, &sc->sc_game_ioh, NULL, NULL)) { 275 aprint_error("%s: can't map Game I/O space\n", 276 sc->sc_dev.dv_xname); 277 return; 278 } 279 280 sc->sc_dmat = pa->pa_dmat; 281 sc->sc_dmas = NULL; 282 sc->sc_dmac_configured = 0; 283 284 /* Enable bus mastering. */ 285 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 286 pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 287 PCI_COMMAND_MASTER_ENABLE); 288 289 /* Reset the device; bail out upon failure. */ 290 if (eso_reset(sc) != 0) { 291 aprint_error("%s: can't reset\n", sc->sc_dev.dv_xname); 292 return; 293 } 294 295 /* Select the DMA/IRQ policy: DDMA, ISA IRQ emulation disabled. */ 296 pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_S1C, 297 pci_conf_read(pa->pa_pc, pa->pa_tag, ESO_PCI_S1C) & 298 ~(ESO_PCI_S1C_IRQP_MASK | ESO_PCI_S1C_DMAP_MASK)); 299 300 /* Enable the relevant (DMA) interrupts. */ 301 bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL, 302 ESO_IO_IRQCTL_A1IRQ | ESO_IO_IRQCTL_A2IRQ | ESO_IO_IRQCTL_HVIRQ | 303 ESO_IO_IRQCTL_MPUIRQ); 304 305 /* Set up A1's sample rate generator for new-style parameters. */ 306 a2mode = eso_read_mixreg(sc, ESO_MIXREG_A2MODE); 307 a2mode |= ESO_MIXREG_A2MODE_NEWA1 | ESO_MIXREG_A2MODE_ASYNC; 308 eso_write_mixreg(sc, ESO_MIXREG_A2MODE, a2mode); 309 310 /* Slave Master Volume to Hardware Volume Control Counter, unmask IRQ.*/ 311 mvctl = eso_read_mixreg(sc, ESO_MIXREG_MVCTL); 312 mvctl &= ~ESO_MIXREG_MVCTL_SPLIT; 313 mvctl |= ESO_MIXREG_MVCTL_HVIRQM; 314 eso_write_mixreg(sc, ESO_MIXREG_MVCTL, mvctl); 315 316 /* Set mixer regs to something reasonable, needs work. */ 317 sc->sc_recmon = sc->sc_spatializer = sc->sc_mvmute = 0; 318 eso_set_monooutsrc(sc, ESO_MIXREG_MPM_MOMUTE); 319 eso_set_monoinbypass(sc, 0); 320 eso_set_preamp(sc, 1); 321 for (idx = 0; idx < ESO_NGAINDEVS; idx++) { 322 int v; 323 324 switch (idx) { 325 case ESO_MIC_PLAY_VOL: 326 case ESO_LINE_PLAY_VOL: 327 case ESO_CD_PLAY_VOL: 328 case ESO_MONO_PLAY_VOL: 329 case ESO_AUXB_PLAY_VOL: 330 case ESO_DAC_REC_VOL: 331 case ESO_LINE_REC_VOL: 332 case ESO_SYNTH_REC_VOL: 333 case ESO_CD_REC_VOL: 334 case ESO_MONO_REC_VOL: 335 case ESO_AUXB_REC_VOL: 336 case ESO_SPATIALIZER: 337 v = 0; 338 break; 339 case ESO_MASTER_VOL: 340 v = ESO_GAIN_TO_6BIT(AUDIO_MAX_GAIN / 2); 341 break; 342 default: 343 v = ESO_GAIN_TO_4BIT(AUDIO_MAX_GAIN / 2); 344 break; 345 } 346 sc->sc_gain[idx][ESO_LEFT] = sc->sc_gain[idx][ESO_RIGHT] = v; 347 eso_set_gain(sc, idx); 348 } 349 eso_set_recsrc(sc, ESO_MIXREG_ERS_MIC); 350 351 /* Map and establish the interrupt. */ 352 if (pci_intr_map(pa, &ih)) { 353 aprint_error("%s: couldn't map interrupt\n", 354 sc->sc_dev.dv_xname); 355 return; 356 } 357 intrstring = pci_intr_string(pa->pa_pc, ih); 358 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_AUDIO, eso_intr, sc); 359 if (sc->sc_ih == NULL) { 360 aprint_error("%s: couldn't establish interrupt", 361 sc->sc_dev.dv_xname); 362 if (intrstring != NULL) 363 aprint_normal(" at %s", intrstring); 364 aprint_normal("\n"); 365 return; 366 } 367 aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, 368 intrstring); 369 370 /* 371 * Set up the DDMA Control register; a suitable I/O region has been 372 * supposedly mapped in the VC base address register. 373 * 374 * The Solo-1 has an ... interesting silicon bug that causes it to 375 * not respond to I/O space accesses to the Audio 1 DMA controller 376 * if the latter's mapping base address is aligned on a 1K boundary. 377 * As a consequence, it is quite possible for the mapping provided 378 * in the VC BAR to be useless. To work around this, we defer this 379 * part until all autoconfiguration on our parent bus is completed 380 * and then try to map it ourselves in fulfillment of the constraint. 381 * 382 * According to the register map we may write to the low 16 bits 383 * only, but experimenting has shown we're safe. 384 * -kjk 385 */ 386 if (ESO_VALID_DDMAC_BASE(vcbase)) { 387 pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_DDMAC, 388 vcbase | ESO_PCI_DDMAC_DE); 389 sc->sc_dmac_configured = 1; 390 391 aprint_normal( 392 "%s: mapping Audio 1 DMA using VC I/O space at 0x%lx\n", 393 sc->sc_dev.dv_xname, (unsigned long)vcbase); 394 } else { 395 DPRINTF(("%s: VC I/O space at 0x%lx not suitable, deferring\n", 396 sc->sc_dev.dv_xname, (unsigned long)vcbase)); 397 sc->sc_pa = *pa; 398 config_defer(self, eso_defer); 399 } 400 401 audio_attach_mi(&eso_hw_if, sc, &sc->sc_dev); 402 403 aa.type = AUDIODEV_TYPE_OPL; 404 aa.hwif = NULL; 405 aa.hdl = NULL; 406 (void)config_found(&sc->sc_dev, &aa, audioprint); 407 408 aa.type = AUDIODEV_TYPE_MPU; 409 aa.hwif = NULL; 410 aa.hdl = NULL; 411 sc->sc_mpudev = config_found(&sc->sc_dev, &aa, audioprint); 412 if (sc->sc_mpudev != NULL) { 413 /* Unmask the MPU irq. */ 414 mvctl = eso_read_mixreg(sc, ESO_MIXREG_MVCTL); 415 mvctl |= ESO_MIXREG_MVCTL_MPUIRQM; 416 eso_write_mixreg(sc, ESO_MIXREG_MVCTL, mvctl); 417 } 418 419 aa.type = AUDIODEV_TYPE_AUX; 420 aa.hwif = NULL; 421 aa.hdl = NULL; 422 (void)config_found(&sc->sc_dev, &aa, eso_print); 423 } 424 425 static void 426 eso_defer(struct device *self) 427 { 428 struct eso_softc *sc; 429 struct pci_attach_args *pa; 430 bus_addr_t addr, start; 431 432 sc = (struct eso_softc *)self; 433 pa = &sc->sc_pa; 434 aprint_normal("%s: ", sc->sc_dev.dv_xname); 435 436 /* 437 * This is outright ugly, but since we must not make assumptions 438 * on the underlying allocator's behaviour it's the most straight- 439 * forward way to implement it. Note that we skip over the first 440 * 1K region, which is typically occupied by an attached ISA bus. 441 */ 442 for (start = 0x0400; start < 0xffff; start += 0x0400) { 443 if (bus_space_alloc(sc->sc_iot, 444 start + sc->sc_vcsize, start + 0x0400 - 1, 445 sc->sc_vcsize, sc->sc_vcsize, 0, 0, &addr, 446 &sc->sc_dmac_ioh) != 0) 447 continue; 448 449 pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_DDMAC, 450 addr | ESO_PCI_DDMAC_DE); 451 sc->sc_dmac_iot = sc->sc_iot; 452 sc->sc_dmac_configured = 1; 453 aprint_normal("mapping Audio 1 DMA using I/O space at 0x%lx\n", 454 (unsigned long)addr); 455 456 return; 457 } 458 459 aprint_error("can't map Audio 1 DMA into I/O space\n"); 460 } 461 462 /* ARGSUSED */ 463 static int 464 eso_print(void *aux, const char *pnp) 465 { 466 467 /* Only joys can attach via this; easy. */ 468 if (pnp) 469 aprint_normal("joy at %s:", pnp); 470 471 return UNCONF; 472 } 473 474 static void 475 eso_write_cmd(struct eso_softc *sc, uint8_t cmd) 476 { 477 int i; 478 479 /* Poll for busy indicator to become clear. */ 480 for (i = 0; i < ESO_WDR_TIMEOUT; i++) { 481 if ((bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RSR) 482 & ESO_SB_RSR_BUSY) == 0) { 483 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, 484 ESO_SB_WDR, cmd); 485 return; 486 } else { 487 delay(10); 488 } 489 } 490 491 printf("%s: WDR timeout\n", sc->sc_dev.dv_xname); 492 return; 493 } 494 495 /* Write to a controller register */ 496 static void 497 eso_write_ctlreg(struct eso_softc *sc, uint8_t reg, uint8_t val) 498 { 499 500 /* DPRINTF(("ctlreg 0x%02x = 0x%02x\n", reg, val)); */ 501 502 eso_write_cmd(sc, reg); 503 eso_write_cmd(sc, val); 504 } 505 506 /* Read out the Read Data Register */ 507 static uint8_t 508 eso_read_rdr(struct eso_softc *sc) 509 { 510 int i; 511 512 for (i = 0; i < ESO_RDR_TIMEOUT; i++) { 513 if (bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, 514 ESO_SB_RBSR) & ESO_SB_RBSR_RDAV) { 515 return (bus_space_read_1(sc->sc_sb_iot, 516 sc->sc_sb_ioh, ESO_SB_RDR)); 517 } else { 518 delay(10); 519 } 520 } 521 522 printf("%s: RDR timeout\n", sc->sc_dev.dv_xname); 523 return (-1); 524 } 525 526 static uint8_t 527 eso_read_ctlreg(struct eso_softc *sc, uint8_t reg) 528 { 529 530 eso_write_cmd(sc, ESO_CMD_RCR); 531 eso_write_cmd(sc, reg); 532 return eso_read_rdr(sc); 533 } 534 535 static void 536 eso_write_mixreg(struct eso_softc *sc, uint8_t reg, uint8_t val) 537 { 538 int s; 539 540 /* DPRINTF(("mixreg 0x%02x = 0x%02x\n", reg, val)); */ 541 542 s = splaudio(); 543 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERADDR, reg); 544 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERDATA, val); 545 splx(s); 546 } 547 548 static uint8_t 549 eso_read_mixreg(struct eso_softc *sc, uint8_t reg) 550 { 551 int s; 552 uint8_t val; 553 554 s = splaudio(); 555 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERADDR, reg); 556 val = bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERDATA); 557 splx(s); 558 559 return val; 560 } 561 562 static int 563 eso_intr(void *hdl) 564 { 565 struct eso_softc *sc; 566 uint8_t irqctl; 567 568 sc = hdl; 569 irqctl = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL); 570 571 /* If it wasn't ours, that's all she wrote. */ 572 if ((irqctl & (ESO_IO_IRQCTL_A1IRQ | ESO_IO_IRQCTL_A2IRQ | 573 ESO_IO_IRQCTL_HVIRQ | ESO_IO_IRQCTL_MPUIRQ)) == 0) 574 return 0; 575 576 if (irqctl & ESO_IO_IRQCTL_A1IRQ) { 577 /* Clear interrupt. */ 578 (void)bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, 579 ESO_SB_RBSR); 580 581 if (sc->sc_rintr) 582 sc->sc_rintr(sc->sc_rarg); 583 else 584 wakeup(&sc->sc_rintr); 585 } 586 587 if (irqctl & ESO_IO_IRQCTL_A2IRQ) { 588 /* 589 * Clear the A2 IRQ latch: the cached value reflects the 590 * current DAC settings with the IRQ latch bit not set. 591 */ 592 eso_write_mixreg(sc, ESO_MIXREG_A2C2, sc->sc_a2c2); 593 594 if (sc->sc_pintr) 595 sc->sc_pintr(sc->sc_parg); 596 else 597 wakeup(&sc->sc_pintr); 598 } 599 600 if (irqctl & ESO_IO_IRQCTL_HVIRQ) { 601 /* Clear interrupt. */ 602 eso_write_mixreg(sc, ESO_MIXREG_CHVIR, ESO_MIXREG_CHVIR_CHVIR); 603 604 /* 605 * Raise a flag to cause a lazy update of the in-softc gain 606 * values the next time the software mixer is read to keep 607 * interrupt service cost low. ~0 cannot occur otherwise 608 * as the master volume has a precision of 6 bits only. 609 */ 610 sc->sc_gain[ESO_MASTER_VOL][ESO_LEFT] = (uint8_t)~0; 611 } 612 613 #if NMPU > 0 614 if ((irqctl & ESO_IO_IRQCTL_MPUIRQ) && sc->sc_mpudev != NULL) 615 mpu_intr(sc->sc_mpudev); 616 #endif 617 618 return 1; 619 } 620 621 /* Perform a software reset, including DMA FIFOs. */ 622 static int 623 eso_reset(struct eso_softc *sc) 624 { 625 int i; 626 627 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RESET, 628 ESO_SB_RESET_SW | ESO_SB_RESET_FIFO); 629 /* `Delay' suggested in the data sheet. */ 630 (void)bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_STATUS); 631 bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RESET, 0); 632 633 /* Wait for reset to take effect. */ 634 for (i = 0; i < ESO_RESET_TIMEOUT; i++) { 635 /* Poll for data to become available. */ 636 if ((bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, 637 ESO_SB_RBSR) & ESO_SB_RBSR_RDAV) != 0 && 638 bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, 639 ESO_SB_RDR) == ESO_SB_RDR_RESETMAGIC) { 640 641 /* Activate Solo-1 extension commands. */ 642 eso_write_cmd(sc, ESO_CMD_EXTENB); 643 /* Reset mixer registers. */ 644 eso_write_mixreg(sc, ESO_MIXREG_RESET, 645 ESO_MIXREG_RESET_RESET); 646 647 return 0; 648 } else { 649 delay(1000); 650 } 651 } 652 653 printf("%s: reset timeout\n", sc->sc_dev.dv_xname); 654 return -1; 655 } 656 657 static int 658 eso_query_encoding(void *hdl, struct audio_encoding *fp) 659 { 660 661 switch (fp->index) { 662 case 0: 663 strcpy(fp->name, AudioEulinear); 664 fp->encoding = AUDIO_ENCODING_ULINEAR; 665 fp->precision = 8; 666 fp->flags = 0; 667 break; 668 case 1: 669 strcpy(fp->name, AudioEmulaw); 670 fp->encoding = AUDIO_ENCODING_ULAW; 671 fp->precision = 8; 672 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 673 break; 674 case 2: 675 strcpy(fp->name, AudioEalaw); 676 fp->encoding = AUDIO_ENCODING_ALAW; 677 fp->precision = 8; 678 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 679 break; 680 case 3: 681 strcpy(fp->name, AudioEslinear); 682 fp->encoding = AUDIO_ENCODING_SLINEAR; 683 fp->precision = 8; 684 fp->flags = 0; 685 break; 686 case 4: 687 strcpy(fp->name, AudioEslinear_le); 688 fp->encoding = AUDIO_ENCODING_SLINEAR_LE; 689 fp->precision = 16; 690 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 691 break; 692 case 5: 693 strcpy(fp->name, AudioEulinear_le); 694 fp->encoding = AUDIO_ENCODING_ULINEAR_LE; 695 fp->precision = 16; 696 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 697 break; 698 case 6: 699 strcpy(fp->name, AudioEslinear_be); 700 fp->encoding = AUDIO_ENCODING_SLINEAR_BE; 701 fp->precision = 16; 702 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 703 break; 704 case 7: 705 strcpy(fp->name, AudioEulinear_be); 706 fp->encoding = AUDIO_ENCODING_ULINEAR_BE; 707 fp->precision = 16; 708 fp->flags = AUDIO_ENCODINGFLAG_EMULATED; 709 break; 710 default: 711 return EINVAL; 712 } 713 714 return 0; 715 } 716 717 static int 718 eso_set_params(void *hdl, int setmode, int usemode, audio_params_t *play, 719 audio_params_t *rec, stream_filter_list_t *pfil, stream_filter_list_t *rfil) 720 { 721 struct eso_softc *sc; 722 struct audio_params *p; 723 stream_filter_list_t *fil; 724 int mode, r[2], rd[2], clk; 725 unsigned int srg, fltdiv; 726 int i; 727 728 sc = hdl; 729 for (mode = AUMODE_RECORD; mode != -1; 730 mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) { 731 if ((setmode & mode) == 0) 732 continue; 733 734 p = (mode == AUMODE_PLAY) ? play : rec; 735 736 if (p->sample_rate < ESO_MINRATE || 737 p->sample_rate > ESO_MAXRATE || 738 (p->precision != 8 && p->precision != 16) || 739 (p->channels != 1 && p->channels != 2)) 740 return EINVAL; 741 742 /* 743 * We'll compute both possible sample rate dividers and pick 744 * the one with the least error. 745 */ 746 #define ABS(x) ((x) < 0 ? -(x) : (x)) 747 r[0] = ESO_CLK0 / 748 (128 - (rd[0] = 128 - ESO_CLK0 / p->sample_rate)); 749 r[1] = ESO_CLK1 / 750 (128 - (rd[1] = 128 - ESO_CLK1 / p->sample_rate)); 751 752 clk = ABS(p->sample_rate - r[0]) > ABS(p->sample_rate - r[1]); 753 srg = rd[clk] | (clk == 1 ? ESO_CLK1_SELECT : 0x00); 754 755 /* Roll-off frequency of 87%, as in the ES1888 driver. */ 756 fltdiv = 256 - 200279L / r[clk]; 757 758 /* Update to reflect the possibly inexact rate. */ 759 p->sample_rate = r[clk]; 760 761 fil = (mode == AUMODE_PLAY) ? pfil : rfil; 762 i = auconv_set_converter(eso_formats, ESO_NFORMATS, 763 mode, p, FALSE, fil); 764 if (i < 0) 765 return EINVAL; 766 if (mode == AUMODE_RECORD) { 767 /* Audio 1 */ 768 DPRINTF(("A1 srg 0x%02x fdiv 0x%02x\n", srg, fltdiv)); 769 eso_write_ctlreg(sc, ESO_CTLREG_SRG, srg); 770 eso_write_ctlreg(sc, ESO_CTLREG_FLTDIV, fltdiv); 771 } else { 772 /* Audio 2 */ 773 DPRINTF(("A2 srg 0x%02x fdiv 0x%02x\n", srg, fltdiv)); 774 eso_write_mixreg(sc, ESO_MIXREG_A2SRG, srg); 775 eso_write_mixreg(sc, ESO_MIXREG_A2FLTDIV, fltdiv); 776 } 777 #undef ABS 778 779 } 780 781 return 0; 782 } 783 784 static int 785 eso_round_blocksize(void *hdl, int blk, int mode, const audio_params_t *param) 786 { 787 788 return blk & -32; /* keep good alignment; at least 16 req'd */ 789 } 790 791 static int 792 eso_halt_output(void *hdl) 793 { 794 struct eso_softc *sc; 795 int error, s; 796 797 sc = hdl; 798 DPRINTF(("%s: halt_output\n", sc->sc_dev.dv_xname)); 799 800 /* 801 * Disable auto-initialize DMA, allowing the FIFO to drain and then 802 * stop. The interrupt callback pointer is cleared at this 803 * point so that an outstanding FIFO interrupt for the remaining data 804 * will be acknowledged without further processing. 805 * 806 * This does not immediately `abort' an operation in progress (c.f. 807 * audio(9)) but is the method to leave the FIFO behind in a clean 808 * state with the least hair. (Besides, that item needs to be 809 * rephrased for trigger_*()-based DMA environments.) 810 */ 811 s = splaudio(); 812 eso_write_mixreg(sc, ESO_MIXREG_A2C1, 813 ESO_MIXREG_A2C1_FIFOENB | ESO_MIXREG_A2C1_DMAENB); 814 bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM, 815 ESO_IO_A2DMAM_DMAENB); 816 817 sc->sc_pintr = NULL; 818 error = tsleep(&sc->sc_pintr, PCATCH | PWAIT, "esoho", sc->sc_pdrain); 819 splx(s); 820 821 /* Shut down DMA completely. */ 822 eso_write_mixreg(sc, ESO_MIXREG_A2C1, 0); 823 bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM, 0); 824 825 return error == EWOULDBLOCK ? 0 : error; 826 } 827 828 static int 829 eso_halt_input(void *hdl) 830 { 831 struct eso_softc *sc; 832 int error, s; 833 834 sc = hdl; 835 DPRINTF(("%s: halt_input\n", sc->sc_dev.dv_xname)); 836 837 /* Just like eso_halt_output(), but for Audio 1. */ 838 s = splaudio(); 839 eso_write_ctlreg(sc, ESO_CTLREG_A1C2, 840 ESO_CTLREG_A1C2_READ | ESO_CTLREG_A1C2_ADC | 841 ESO_CTLREG_A1C2_DMAENB); 842 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MODE, 843 DMA37MD_WRITE | DMA37MD_DEMAND); 844 845 sc->sc_rintr = NULL; 846 error = tsleep(&sc->sc_rintr, PCATCH | PWAIT, "esohi", sc->sc_rdrain); 847 splx(s); 848 849 /* Shut down DMA completely. */ 850 eso_write_ctlreg(sc, ESO_CTLREG_A1C2, 851 ESO_CTLREG_A1C2_READ | ESO_CTLREG_A1C2_ADC); 852 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK, 853 ESO_DMAC_MASK_MASK); 854 855 return error == EWOULDBLOCK ? 0 : error; 856 } 857 858 static int 859 eso_getdev(void *hdl, struct audio_device *retp) 860 { 861 struct eso_softc *sc; 862 863 sc = hdl; 864 strncpy(retp->name, "ESS Solo-1", sizeof (retp->name)); 865 snprintf(retp->version, sizeof (retp->version), "0x%02x", 866 sc->sc_revision); 867 if (sc->sc_revision < 868 sizeof (eso_rev2model) / sizeof (eso_rev2model[0])) 869 strncpy(retp->config, eso_rev2model[sc->sc_revision], 870 sizeof (retp->config)); 871 else 872 strncpy(retp->config, "unknown", sizeof (retp->config)); 873 874 return 0; 875 } 876 877 static int 878 eso_set_port(void *hdl, mixer_ctrl_t *cp) 879 { 880 struct eso_softc *sc; 881 unsigned int lgain, rgain; 882 uint8_t tmp; 883 884 sc = hdl; 885 switch (cp->dev) { 886 case ESO_DAC_PLAY_VOL: 887 case ESO_MIC_PLAY_VOL: 888 case ESO_LINE_PLAY_VOL: 889 case ESO_SYNTH_PLAY_VOL: 890 case ESO_CD_PLAY_VOL: 891 case ESO_AUXB_PLAY_VOL: 892 case ESO_RECORD_VOL: 893 case ESO_DAC_REC_VOL: 894 case ESO_MIC_REC_VOL: 895 case ESO_LINE_REC_VOL: 896 case ESO_SYNTH_REC_VOL: 897 case ESO_CD_REC_VOL: 898 case ESO_AUXB_REC_VOL: 899 if (cp->type != AUDIO_MIXER_VALUE) 900 return EINVAL; 901 902 /* 903 * Stereo-capable mixer ports: if we get a single-channel 904 * gain value passed in, then we duplicate it to both left 905 * and right channels. 906 */ 907 switch (cp->un.value.num_channels) { 908 case 1: 909 lgain = rgain = ESO_GAIN_TO_4BIT( 910 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]); 911 break; 912 case 2: 913 lgain = ESO_GAIN_TO_4BIT( 914 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]); 915 rgain = ESO_GAIN_TO_4BIT( 916 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]); 917 break; 918 default: 919 return EINVAL; 920 } 921 922 sc->sc_gain[cp->dev][ESO_LEFT] = lgain; 923 sc->sc_gain[cp->dev][ESO_RIGHT] = rgain; 924 eso_set_gain(sc, cp->dev); 925 break; 926 927 case ESO_MASTER_VOL: 928 if (cp->type != AUDIO_MIXER_VALUE) 929 return EINVAL; 930 931 /* Like above, but a precision of 6 bits. */ 932 switch (cp->un.value.num_channels) { 933 case 1: 934 lgain = rgain = ESO_GAIN_TO_6BIT( 935 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]); 936 break; 937 case 2: 938 lgain = ESO_GAIN_TO_6BIT( 939 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]); 940 rgain = ESO_GAIN_TO_6BIT( 941 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]); 942 break; 943 default: 944 return EINVAL; 945 } 946 947 sc->sc_gain[cp->dev][ESO_LEFT] = lgain; 948 sc->sc_gain[cp->dev][ESO_RIGHT] = rgain; 949 eso_set_gain(sc, cp->dev); 950 break; 951 952 case ESO_SPATIALIZER: 953 if (cp->type != AUDIO_MIXER_VALUE || 954 cp->un.value.num_channels != 1) 955 return EINVAL; 956 957 sc->sc_gain[cp->dev][ESO_LEFT] = 958 sc->sc_gain[cp->dev][ESO_RIGHT] = 959 ESO_GAIN_TO_6BIT( 960 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]); 961 eso_set_gain(sc, cp->dev); 962 break; 963 964 case ESO_MONO_PLAY_VOL: 965 case ESO_MONO_REC_VOL: 966 if (cp->type != AUDIO_MIXER_VALUE || 967 cp->un.value.num_channels != 1) 968 return EINVAL; 969 970 sc->sc_gain[cp->dev][ESO_LEFT] = 971 sc->sc_gain[cp->dev][ESO_RIGHT] = 972 ESO_GAIN_TO_4BIT( 973 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]); 974 eso_set_gain(sc, cp->dev); 975 break; 976 977 case ESO_PCSPEAKER_VOL: 978 if (cp->type != AUDIO_MIXER_VALUE || 979 cp->un.value.num_channels != 1) 980 return EINVAL; 981 982 sc->sc_gain[cp->dev][ESO_LEFT] = 983 sc->sc_gain[cp->dev][ESO_RIGHT] = 984 ESO_GAIN_TO_3BIT( 985 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]); 986 eso_set_gain(sc, cp->dev); 987 break; 988 989 case ESO_SPATIALIZER_ENABLE: 990 if (cp->type != AUDIO_MIXER_ENUM) 991 return EINVAL; 992 993 sc->sc_spatializer = (cp->un.ord != 0); 994 995 tmp = eso_read_mixreg(sc, ESO_MIXREG_SPAT); 996 if (sc->sc_spatializer) 997 tmp |= ESO_MIXREG_SPAT_ENB; 998 else 999 tmp &= ~ESO_MIXREG_SPAT_ENB; 1000 eso_write_mixreg(sc, ESO_MIXREG_SPAT, 1001 tmp | ESO_MIXREG_SPAT_RSTREL); 1002 break; 1003 1004 case ESO_MASTER_MUTE: 1005 if (cp->type != AUDIO_MIXER_ENUM) 1006 return EINVAL; 1007 1008 sc->sc_mvmute = (cp->un.ord != 0); 1009 1010 if (sc->sc_mvmute) { 1011 eso_write_mixreg(sc, ESO_MIXREG_LMVM, 1012 eso_read_mixreg(sc, ESO_MIXREG_LMVM) | 1013 ESO_MIXREG_LMVM_MUTE); 1014 eso_write_mixreg(sc, ESO_MIXREG_RMVM, 1015 eso_read_mixreg(sc, ESO_MIXREG_RMVM) | 1016 ESO_MIXREG_RMVM_MUTE); 1017 } else { 1018 eso_write_mixreg(sc, ESO_MIXREG_LMVM, 1019 eso_read_mixreg(sc, ESO_MIXREG_LMVM) & 1020 ~ESO_MIXREG_LMVM_MUTE); 1021 eso_write_mixreg(sc, ESO_MIXREG_RMVM, 1022 eso_read_mixreg(sc, ESO_MIXREG_RMVM) & 1023 ~ESO_MIXREG_RMVM_MUTE); 1024 } 1025 break; 1026 1027 case ESO_MONOOUT_SOURCE: 1028 if (cp->type != AUDIO_MIXER_ENUM) 1029 return EINVAL; 1030 1031 return eso_set_monooutsrc(sc, cp->un.ord); 1032 1033 case ESO_MONOIN_BYPASS: 1034 if (cp->type != AUDIO_MIXER_ENUM) 1035 return EINVAL; 1036 1037 return (eso_set_monoinbypass(sc, cp->un.ord)); 1038 1039 case ESO_RECORD_MONITOR: 1040 if (cp->type != AUDIO_MIXER_ENUM) 1041 return EINVAL; 1042 1043 sc->sc_recmon = (cp->un.ord != 0); 1044 1045 tmp = eso_read_ctlreg(sc, ESO_CTLREG_ACTL); 1046 if (sc->sc_recmon) 1047 tmp |= ESO_CTLREG_ACTL_RECMON; 1048 else 1049 tmp &= ~ESO_CTLREG_ACTL_RECMON; 1050 eso_write_ctlreg(sc, ESO_CTLREG_ACTL, tmp); 1051 break; 1052 1053 case ESO_RECORD_SOURCE: 1054 if (cp->type != AUDIO_MIXER_ENUM) 1055 return EINVAL; 1056 1057 return eso_set_recsrc(sc, cp->un.ord); 1058 1059 case ESO_MIC_PREAMP: 1060 if (cp->type != AUDIO_MIXER_ENUM) 1061 return EINVAL; 1062 1063 return eso_set_preamp(sc, cp->un.ord); 1064 1065 default: 1066 return EINVAL; 1067 } 1068 1069 return 0; 1070 } 1071 1072 static int 1073 eso_get_port(void *hdl, mixer_ctrl_t *cp) 1074 { 1075 struct eso_softc *sc; 1076 1077 sc = hdl; 1078 switch (cp->dev) { 1079 case ESO_MASTER_VOL: 1080 /* Reload from mixer after hardware volume control use. */ 1081 if (sc->sc_gain[cp->dev][ESO_LEFT] == (uint8_t)~0) 1082 eso_reload_master_vol(sc); 1083 /* FALLTHROUGH */ 1084 case ESO_DAC_PLAY_VOL: 1085 case ESO_MIC_PLAY_VOL: 1086 case ESO_LINE_PLAY_VOL: 1087 case ESO_SYNTH_PLAY_VOL: 1088 case ESO_CD_PLAY_VOL: 1089 case ESO_AUXB_PLAY_VOL: 1090 case ESO_RECORD_VOL: 1091 case ESO_DAC_REC_VOL: 1092 case ESO_MIC_REC_VOL: 1093 case ESO_LINE_REC_VOL: 1094 case ESO_SYNTH_REC_VOL: 1095 case ESO_CD_REC_VOL: 1096 case ESO_AUXB_REC_VOL: 1097 /* 1098 * Stereo-capable ports: if a single-channel query is made, 1099 * just return the left channel's value (since single-channel 1100 * settings themselves are applied to both channels). 1101 */ 1102 switch (cp->un.value.num_channels) { 1103 case 1: 1104 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = 1105 sc->sc_gain[cp->dev][ESO_LEFT]; 1106 break; 1107 case 2: 1108 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 1109 sc->sc_gain[cp->dev][ESO_LEFT]; 1110 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 1111 sc->sc_gain[cp->dev][ESO_RIGHT]; 1112 break; 1113 default: 1114 return EINVAL; 1115 } 1116 break; 1117 1118 case ESO_MONO_PLAY_VOL: 1119 case ESO_PCSPEAKER_VOL: 1120 case ESO_MONO_REC_VOL: 1121 case ESO_SPATIALIZER: 1122 if (cp->un.value.num_channels != 1) 1123 return EINVAL; 1124 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = 1125 sc->sc_gain[cp->dev][ESO_LEFT]; 1126 break; 1127 1128 case ESO_RECORD_MONITOR: 1129 cp->un.ord = sc->sc_recmon; 1130 break; 1131 1132 case ESO_RECORD_SOURCE: 1133 cp->un.ord = sc->sc_recsrc; 1134 break; 1135 1136 case ESO_MONOOUT_SOURCE: 1137 cp->un.ord = sc->sc_monooutsrc; 1138 break; 1139 1140 case ESO_MONOIN_BYPASS: 1141 cp->un.ord = sc->sc_monoinbypass; 1142 break; 1143 1144 case ESO_SPATIALIZER_ENABLE: 1145 cp->un.ord = sc->sc_spatializer; 1146 break; 1147 1148 case ESO_MIC_PREAMP: 1149 cp->un.ord = sc->sc_preamp; 1150 break; 1151 1152 case ESO_MASTER_MUTE: 1153 /* Reload from mixer after hardware volume control use. */ 1154 eso_reload_master_vol(sc); 1155 cp->un.ord = sc->sc_mvmute; 1156 break; 1157 1158 default: 1159 return EINVAL; 1160 } 1161 1162 return 0; 1163 } 1164 1165 static int 1166 eso_query_devinfo(void *hdl, mixer_devinfo_t *dip) 1167 { 1168 1169 switch (dip->index) { 1170 case ESO_DAC_PLAY_VOL: 1171 dip->mixer_class = ESO_INPUT_CLASS; 1172 dip->next = dip->prev = AUDIO_MIXER_LAST; 1173 strcpy(dip->label.name, AudioNdac); 1174 dip->type = AUDIO_MIXER_VALUE; 1175 dip->un.v.num_channels = 2; 1176 strcpy(dip->un.v.units.name, AudioNvolume); 1177 break; 1178 case ESO_MIC_PLAY_VOL: 1179 dip->mixer_class = ESO_INPUT_CLASS; 1180 dip->next = dip->prev = AUDIO_MIXER_LAST; 1181 strcpy(dip->label.name, AudioNmicrophone); 1182 dip->type = AUDIO_MIXER_VALUE; 1183 dip->un.v.num_channels = 2; 1184 strcpy(dip->un.v.units.name, AudioNvolume); 1185 break; 1186 case ESO_LINE_PLAY_VOL: 1187 dip->mixer_class = ESO_INPUT_CLASS; 1188 dip->next = dip->prev = AUDIO_MIXER_LAST; 1189 strcpy(dip->label.name, AudioNline); 1190 dip->type = AUDIO_MIXER_VALUE; 1191 dip->un.v.num_channels = 2; 1192 strcpy(dip->un.v.units.name, AudioNvolume); 1193 break; 1194 case ESO_SYNTH_PLAY_VOL: 1195 dip->mixer_class = ESO_INPUT_CLASS; 1196 dip->next = dip->prev = AUDIO_MIXER_LAST; 1197 strcpy(dip->label.name, AudioNfmsynth); 1198 dip->type = AUDIO_MIXER_VALUE; 1199 dip->un.v.num_channels = 2; 1200 strcpy(dip->un.v.units.name, AudioNvolume); 1201 break; 1202 case ESO_MONO_PLAY_VOL: 1203 dip->mixer_class = ESO_INPUT_CLASS; 1204 dip->next = dip->prev = AUDIO_MIXER_LAST; 1205 strcpy(dip->label.name, "mono_in"); 1206 dip->type = AUDIO_MIXER_VALUE; 1207 dip->un.v.num_channels = 1; 1208 strcpy(dip->un.v.units.name, AudioNvolume); 1209 break; 1210 case ESO_CD_PLAY_VOL: 1211 dip->mixer_class = ESO_INPUT_CLASS; 1212 dip->next = dip->prev = AUDIO_MIXER_LAST; 1213 strcpy(dip->label.name, AudioNcd); 1214 dip->type = AUDIO_MIXER_VALUE; 1215 dip->un.v.num_channels = 2; 1216 strcpy(dip->un.v.units.name, AudioNvolume); 1217 break; 1218 case ESO_AUXB_PLAY_VOL: 1219 dip->mixer_class = ESO_INPUT_CLASS; 1220 dip->next = dip->prev = AUDIO_MIXER_LAST; 1221 strcpy(dip->label.name, "auxb"); 1222 dip->type = AUDIO_MIXER_VALUE; 1223 dip->un.v.num_channels = 2; 1224 strcpy(dip->un.v.units.name, AudioNvolume); 1225 break; 1226 1227 case ESO_MIC_PREAMP: 1228 dip->mixer_class = ESO_MICROPHONE_CLASS; 1229 dip->next = dip->prev = AUDIO_MIXER_LAST; 1230 strcpy(dip->label.name, AudioNpreamp); 1231 dip->type = AUDIO_MIXER_ENUM; 1232 dip->un.e.num_mem = 2; 1233 strcpy(dip->un.e.member[0].label.name, AudioNoff); 1234 dip->un.e.member[0].ord = 0; 1235 strcpy(dip->un.e.member[1].label.name, AudioNon); 1236 dip->un.e.member[1].ord = 1; 1237 break; 1238 case ESO_MICROPHONE_CLASS: 1239 dip->mixer_class = ESO_MICROPHONE_CLASS; 1240 dip->next = dip->prev = AUDIO_MIXER_LAST; 1241 strcpy(dip->label.name, AudioNmicrophone); 1242 dip->type = AUDIO_MIXER_CLASS; 1243 break; 1244 1245 case ESO_INPUT_CLASS: 1246 dip->mixer_class = ESO_INPUT_CLASS; 1247 dip->next = dip->prev = AUDIO_MIXER_LAST; 1248 strcpy(dip->label.name, AudioCinputs); 1249 dip->type = AUDIO_MIXER_CLASS; 1250 break; 1251 1252 case ESO_MASTER_VOL: 1253 dip->mixer_class = ESO_OUTPUT_CLASS; 1254 dip->prev = AUDIO_MIXER_LAST; 1255 dip->next = ESO_MASTER_MUTE; 1256 strcpy(dip->label.name, AudioNmaster); 1257 dip->type = AUDIO_MIXER_VALUE; 1258 dip->un.v.num_channels = 2; 1259 strcpy(dip->un.v.units.name, AudioNvolume); 1260 break; 1261 case ESO_MASTER_MUTE: 1262 dip->mixer_class = ESO_OUTPUT_CLASS; 1263 dip->prev = ESO_MASTER_VOL; 1264 dip->next = AUDIO_MIXER_LAST; 1265 strcpy(dip->label.name, AudioNmute); 1266 dip->type = AUDIO_MIXER_ENUM; 1267 dip->un.e.num_mem = 2; 1268 strcpy(dip->un.e.member[0].label.name, AudioNoff); 1269 dip->un.e.member[0].ord = 0; 1270 strcpy(dip->un.e.member[1].label.name, AudioNon); 1271 dip->un.e.member[1].ord = 1; 1272 break; 1273 1274 case ESO_PCSPEAKER_VOL: 1275 dip->mixer_class = ESO_OUTPUT_CLASS; 1276 dip->next = dip->prev = AUDIO_MIXER_LAST; 1277 strcpy(dip->label.name, "pc_speaker"); 1278 dip->type = AUDIO_MIXER_VALUE; 1279 dip->un.v.num_channels = 1; 1280 strcpy(dip->un.v.units.name, AudioNvolume); 1281 break; 1282 case ESO_MONOOUT_SOURCE: 1283 dip->mixer_class = ESO_OUTPUT_CLASS; 1284 dip->next = dip->prev = AUDIO_MIXER_LAST; 1285 strcpy(dip->label.name, "mono_out"); 1286 dip->type = AUDIO_MIXER_ENUM; 1287 dip->un.e.num_mem = 3; 1288 strcpy(dip->un.e.member[0].label.name, AudioNmute); 1289 dip->un.e.member[0].ord = ESO_MIXREG_MPM_MOMUTE; 1290 strcpy(dip->un.e.member[1].label.name, AudioNdac); 1291 dip->un.e.member[1].ord = ESO_MIXREG_MPM_MOA2R; 1292 strcpy(dip->un.e.member[2].label.name, AudioNmixerout); 1293 dip->un.e.member[2].ord = ESO_MIXREG_MPM_MOREC; 1294 break; 1295 1296 case ESO_MONOIN_BYPASS: 1297 dip->mixer_class = ESO_MONOIN_CLASS; 1298 dip->next = dip->prev = AUDIO_MIXER_LAST; 1299 strcpy(dip->label.name, "bypass"); 1300 dip->type = AUDIO_MIXER_ENUM; 1301 dip->un.e.num_mem = 2; 1302 strcpy(dip->un.e.member[0].label.name, AudioNoff); 1303 dip->un.e.member[0].ord = 0; 1304 strcpy(dip->un.e.member[1].label.name, AudioNon); 1305 dip->un.e.member[1].ord = 1; 1306 break; 1307 case ESO_MONOIN_CLASS: 1308 dip->mixer_class = ESO_MONOIN_CLASS; 1309 dip->next = dip->prev = AUDIO_MIXER_LAST; 1310 strcpy(dip->label.name, "mono_in"); 1311 dip->type = AUDIO_MIXER_CLASS; 1312 break; 1313 1314 case ESO_SPATIALIZER: 1315 dip->mixer_class = ESO_OUTPUT_CLASS; 1316 dip->prev = AUDIO_MIXER_LAST; 1317 dip->next = ESO_SPATIALIZER_ENABLE; 1318 strcpy(dip->label.name, AudioNspatial); 1319 dip->type = AUDIO_MIXER_VALUE; 1320 dip->un.v.num_channels = 1; 1321 strcpy(dip->un.v.units.name, "level"); 1322 break; 1323 case ESO_SPATIALIZER_ENABLE: 1324 dip->mixer_class = ESO_OUTPUT_CLASS; 1325 dip->prev = ESO_SPATIALIZER; 1326 dip->next = AUDIO_MIXER_LAST; 1327 strcpy(dip->label.name, "enable"); 1328 dip->type = AUDIO_MIXER_ENUM; 1329 dip->un.e.num_mem = 2; 1330 strcpy(dip->un.e.member[0].label.name, AudioNoff); 1331 dip->un.e.member[0].ord = 0; 1332 strcpy(dip->un.e.member[1].label.name, AudioNon); 1333 dip->un.e.member[1].ord = 1; 1334 break; 1335 1336 case ESO_OUTPUT_CLASS: 1337 dip->mixer_class = ESO_OUTPUT_CLASS; 1338 dip->next = dip->prev = AUDIO_MIXER_LAST; 1339 strcpy(dip->label.name, AudioCoutputs); 1340 dip->type = AUDIO_MIXER_CLASS; 1341 break; 1342 1343 case ESO_RECORD_MONITOR: 1344 dip->mixer_class = ESO_MONITOR_CLASS; 1345 dip->next = dip->prev = AUDIO_MIXER_LAST; 1346 strcpy(dip->label.name, AudioNmute); 1347 dip->type = AUDIO_MIXER_ENUM; 1348 dip->un.e.num_mem = 2; 1349 strcpy(dip->un.e.member[0].label.name, AudioNoff); 1350 dip->un.e.member[0].ord = 0; 1351 strcpy(dip->un.e.member[1].label.name, AudioNon); 1352 dip->un.e.member[1].ord = 1; 1353 break; 1354 case ESO_MONITOR_CLASS: 1355 dip->mixer_class = ESO_MONITOR_CLASS; 1356 dip->next = dip->prev = AUDIO_MIXER_LAST; 1357 strcpy(dip->label.name, AudioCmonitor); 1358 dip->type = AUDIO_MIXER_CLASS; 1359 break; 1360 1361 case ESO_RECORD_VOL: 1362 dip->mixer_class = ESO_RECORD_CLASS; 1363 dip->next = dip->prev = AUDIO_MIXER_LAST; 1364 strcpy(dip->label.name, AudioNrecord); 1365 dip->type = AUDIO_MIXER_VALUE; 1366 strcpy(dip->un.v.units.name, AudioNvolume); 1367 break; 1368 case ESO_RECORD_SOURCE: 1369 dip->mixer_class = ESO_RECORD_CLASS; 1370 dip->next = dip->prev = AUDIO_MIXER_LAST; 1371 strcpy(dip->label.name, AudioNsource); 1372 dip->type = AUDIO_MIXER_ENUM; 1373 dip->un.e.num_mem = 4; 1374 strcpy(dip->un.e.member[0].label.name, AudioNmicrophone); 1375 dip->un.e.member[0].ord = ESO_MIXREG_ERS_MIC; 1376 strcpy(dip->un.e.member[1].label.name, AudioNline); 1377 dip->un.e.member[1].ord = ESO_MIXREG_ERS_LINE; 1378 strcpy(dip->un.e.member[2].label.name, AudioNcd); 1379 dip->un.e.member[2].ord = ESO_MIXREG_ERS_CD; 1380 strcpy(dip->un.e.member[3].label.name, AudioNmixerout); 1381 dip->un.e.member[3].ord = ESO_MIXREG_ERS_MIXER; 1382 break; 1383 case ESO_DAC_REC_VOL: 1384 dip->mixer_class = ESO_RECORD_CLASS; 1385 dip->next = dip->prev = AUDIO_MIXER_LAST; 1386 strcpy(dip->label.name, AudioNdac); 1387 dip->type = AUDIO_MIXER_VALUE; 1388 dip->un.v.num_channels = 2; 1389 strcpy(dip->un.v.units.name, AudioNvolume); 1390 break; 1391 case ESO_MIC_REC_VOL: 1392 dip->mixer_class = ESO_RECORD_CLASS; 1393 dip->next = dip->prev = AUDIO_MIXER_LAST; 1394 strcpy(dip->label.name, AudioNmicrophone); 1395 dip->type = AUDIO_MIXER_VALUE; 1396 dip->un.v.num_channels = 2; 1397 strcpy(dip->un.v.units.name, AudioNvolume); 1398 break; 1399 case ESO_LINE_REC_VOL: 1400 dip->mixer_class = ESO_RECORD_CLASS; 1401 dip->next = dip->prev = AUDIO_MIXER_LAST; 1402 strcpy(dip->label.name, AudioNline); 1403 dip->type = AUDIO_MIXER_VALUE; 1404 dip->un.v.num_channels = 2; 1405 strcpy(dip->un.v.units.name, AudioNvolume); 1406 break; 1407 case ESO_SYNTH_REC_VOL: 1408 dip->mixer_class = ESO_RECORD_CLASS; 1409 dip->next = dip->prev = AUDIO_MIXER_LAST; 1410 strcpy(dip->label.name, AudioNfmsynth); 1411 dip->type = AUDIO_MIXER_VALUE; 1412 dip->un.v.num_channels = 2; 1413 strcpy(dip->un.v.units.name, AudioNvolume); 1414 break; 1415 case ESO_MONO_REC_VOL: 1416 dip->mixer_class = ESO_RECORD_CLASS; 1417 dip->next = dip->prev = AUDIO_MIXER_LAST; 1418 strcpy(dip->label.name, "mono_in"); 1419 dip->type = AUDIO_MIXER_VALUE; 1420 dip->un.v.num_channels = 1; /* No lies */ 1421 strcpy(dip->un.v.units.name, AudioNvolume); 1422 break; 1423 case ESO_CD_REC_VOL: 1424 dip->mixer_class = ESO_RECORD_CLASS; 1425 dip->next = dip->prev = AUDIO_MIXER_LAST; 1426 strcpy(dip->label.name, AudioNcd); 1427 dip->type = AUDIO_MIXER_VALUE; 1428 dip->un.v.num_channels = 2; 1429 strcpy(dip->un.v.units.name, AudioNvolume); 1430 break; 1431 case ESO_AUXB_REC_VOL: 1432 dip->mixer_class = ESO_RECORD_CLASS; 1433 dip->next = dip->prev = AUDIO_MIXER_LAST; 1434 strcpy(dip->label.name, "auxb"); 1435 dip->type = AUDIO_MIXER_VALUE; 1436 dip->un.v.num_channels = 2; 1437 strcpy(dip->un.v.units.name, AudioNvolume); 1438 break; 1439 case ESO_RECORD_CLASS: 1440 dip->mixer_class = ESO_RECORD_CLASS; 1441 dip->next = dip->prev = AUDIO_MIXER_LAST; 1442 strcpy(dip->label.name, AudioCrecord); 1443 dip->type = AUDIO_MIXER_CLASS; 1444 break; 1445 1446 default: 1447 return ENXIO; 1448 } 1449 1450 return 0; 1451 } 1452 1453 static int 1454 eso_allocmem(struct eso_softc *sc, size_t size, size_t align, size_t boundary, 1455 int flags, int direction, struct eso_dma *ed) 1456 { 1457 int error, wait; 1458 1459 wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK; 1460 ed->ed_size = size; 1461 1462 error = bus_dmamem_alloc(ed->ed_dmat, ed->ed_size, align, boundary, 1463 ed->ed_segs, sizeof (ed->ed_segs) / sizeof (ed->ed_segs[0]), 1464 &ed->ed_nsegs, wait); 1465 if (error) 1466 goto out; 1467 1468 error = bus_dmamem_map(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs, 1469 ed->ed_size, &ed->ed_addr, wait | BUS_DMA_COHERENT); 1470 if (error) 1471 goto free; 1472 1473 error = bus_dmamap_create(ed->ed_dmat, ed->ed_size, 1, ed->ed_size, 0, 1474 wait, &ed->ed_map); 1475 if (error) 1476 goto unmap; 1477 1478 error = bus_dmamap_load(ed->ed_dmat, ed->ed_map, ed->ed_addr, 1479 ed->ed_size, NULL, wait | 1480 (direction == AUMODE_RECORD) ? BUS_DMA_READ : BUS_DMA_WRITE); 1481 if (error) 1482 goto destroy; 1483 1484 return 0; 1485 1486 destroy: 1487 bus_dmamap_destroy(ed->ed_dmat, ed->ed_map); 1488 unmap: 1489 bus_dmamem_unmap(ed->ed_dmat, ed->ed_addr, ed->ed_size); 1490 free: 1491 bus_dmamem_free(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs); 1492 out: 1493 return error; 1494 } 1495 1496 static void 1497 eso_freemem(struct eso_dma *ed) 1498 { 1499 1500 bus_dmamap_unload(ed->ed_dmat, ed->ed_map); 1501 bus_dmamap_destroy(ed->ed_dmat, ed->ed_map); 1502 bus_dmamem_unmap(ed->ed_dmat, ed->ed_addr, ed->ed_size); 1503 bus_dmamem_free(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs); 1504 } 1505 1506 static void * 1507 eso_allocm(void *hdl, int direction, size_t size, struct malloc_type *type, 1508 int flags) 1509 { 1510 struct eso_softc *sc; 1511 struct eso_dma *ed; 1512 size_t boundary; 1513 int error; 1514 1515 sc = hdl; 1516 if ((ed = malloc(sizeof (*ed), type, flags)) == NULL) 1517 return NULL; 1518 1519 /* 1520 * Apparently the Audio 1 DMA controller's current address 1521 * register can't roll over a 64K address boundary, so we have to 1522 * take care of that ourselves. Similarly, the Audio 2 DMA 1523 * controller needs a 1M address boundary. 1524 */ 1525 if (direction == AUMODE_RECORD) 1526 boundary = 0x10000; 1527 else 1528 boundary = 0x100000; 1529 1530 /* 1531 * XXX Work around allocation problems for Audio 1, which 1532 * XXX implements the 24 low address bits only, with 1533 * XXX machine-specific DMA tag use. 1534 */ 1535 #ifdef alpha 1536 /* 1537 * XXX Force allocation through the (ISA) SGMAP. 1538 */ 1539 if (direction == AUMODE_RECORD) 1540 ed->ed_dmat = alphabus_dma_get_tag(sc->sc_dmat, ALPHA_BUS_ISA); 1541 else 1542 #elif defined(amd64) || defined(i386) 1543 /* 1544 * XXX Force allocation through the ISA DMA tag. 1545 */ 1546 if (direction == AUMODE_RECORD) 1547 ed->ed_dmat = &isa_bus_dma_tag; 1548 else 1549 #endif 1550 ed->ed_dmat = sc->sc_dmat; 1551 1552 error = eso_allocmem(sc, size, 32, boundary, flags, direction, ed); 1553 if (error) { 1554 free(ed, type); 1555 return NULL; 1556 } 1557 ed->ed_next = sc->sc_dmas; 1558 sc->sc_dmas = ed; 1559 1560 return KVADDR(ed); 1561 } 1562 1563 static void 1564 eso_freem(void *hdl, void *addr, struct malloc_type *type) 1565 { 1566 struct eso_softc *sc; 1567 struct eso_dma *p, **pp; 1568 1569 sc = hdl; 1570 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->ed_next) { 1571 if (KVADDR(p) == addr) { 1572 eso_freemem(p); 1573 *pp = p->ed_next; 1574 free(p, type); 1575 return; 1576 } 1577 } 1578 } 1579 1580 static size_t 1581 eso_round_buffersize(void *hdl, int direction, size_t bufsize) 1582 { 1583 size_t maxsize; 1584 1585 /* 1586 * The playback DMA buffer size on the Solo-1 is limited to 0xfff0 1587 * bytes. This is because IO_A2DMAC is a two byte value 1588 * indicating the literal byte count, and the 4 least significant 1589 * bits are read-only. Zero is not used as a special case for 1590 * 0x10000. 1591 * 1592 * For recording, DMAC_DMAC is the byte count - 1, so 0x10000 can 1593 * be represented. 1594 */ 1595 maxsize = (direction == AUMODE_PLAY) ? 0xfff0 : 0x10000; 1596 1597 if (bufsize > maxsize) 1598 bufsize = maxsize; 1599 1600 return bufsize; 1601 } 1602 1603 static paddr_t 1604 eso_mappage(void *hdl, void *addr, off_t offs, int prot) 1605 { 1606 struct eso_softc *sc; 1607 struct eso_dma *ed; 1608 1609 sc = hdl; 1610 if (offs < 0) 1611 return -1; 1612 for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != addr; 1613 ed = ed->ed_next) 1614 continue; 1615 if (ed == NULL) 1616 return -1; 1617 1618 return bus_dmamem_mmap(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs, 1619 offs, prot, BUS_DMA_WAITOK); 1620 } 1621 1622 /* ARGSUSED */ 1623 static int 1624 eso_get_props(void *hdl) 1625 { 1626 1627 return AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT | 1628 AUDIO_PROP_FULLDUPLEX; 1629 } 1630 1631 static int 1632 eso_trigger_output(void *hdl, void *start, void *end, int blksize, 1633 void (*intr)(void *), void *arg, const audio_params_t *param) 1634 { 1635 struct eso_softc *sc; 1636 struct eso_dma *ed; 1637 uint8_t a2c1; 1638 1639 sc = hdl; 1640 DPRINTF(( 1641 "%s: trigger_output: start %p, end %p, blksize %d, intr %p(%p)\n", 1642 sc->sc_dev.dv_xname, start, end, blksize, intr, arg)); 1643 DPRINTF(("%s: param: rate %u, encoding %u, precision %u, channels %u\n", 1644 sc->sc_dev.dv_xname, param->sample_rate, param->encoding, 1645 param->precision, param->channels)); 1646 1647 /* Find DMA buffer. */ 1648 for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != start; 1649 ed = ed->ed_next) 1650 continue; 1651 if (ed == NULL) { 1652 printf("%s: trigger_output: bad addr %p\n", 1653 sc->sc_dev.dv_xname, start); 1654 return EINVAL; 1655 } 1656 DPRINTF(("%s: dmaaddr %lx\n", 1657 sc->sc_dev.dv_xname, (unsigned long)DMAADDR(ed))); 1658 1659 sc->sc_pintr = intr; 1660 sc->sc_parg = arg; 1661 1662 /* Compute drain timeout. */ 1663 sc->sc_pdrain = (blksize * NBBY * hz) / 1664 (param->sample_rate * param->channels * 1665 param->precision) + 2; /* slop */ 1666 1667 /* DMA transfer count (in `words'!) reload using 2's complement. */ 1668 blksize = -(blksize >> 1); 1669 eso_write_mixreg(sc, ESO_MIXREG_A2TCRLO, blksize & 0xff); 1670 eso_write_mixreg(sc, ESO_MIXREG_A2TCRHI, blksize >> 8); 1671 1672 /* Update DAC to reflect DMA count and audio parameters. */ 1673 /* Note: we cache A2C2 in order to avoid r/m/w at interrupt time. */ 1674 if (param->precision == 16) 1675 sc->sc_a2c2 |= ESO_MIXREG_A2C2_16BIT; 1676 else 1677 sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_16BIT; 1678 if (param->channels == 2) 1679 sc->sc_a2c2 |= ESO_MIXREG_A2C2_STEREO; 1680 else 1681 sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_STEREO; 1682 if (param->encoding == AUDIO_ENCODING_SLINEAR_BE || 1683 param->encoding == AUDIO_ENCODING_SLINEAR_LE) 1684 sc->sc_a2c2 |= ESO_MIXREG_A2C2_SIGNED; 1685 else 1686 sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_SIGNED; 1687 /* Unmask IRQ. */ 1688 sc->sc_a2c2 |= ESO_MIXREG_A2C2_IRQM; 1689 eso_write_mixreg(sc, ESO_MIXREG_A2C2, sc->sc_a2c2); 1690 1691 /* Set up DMA controller. */ 1692 bus_space_write_4(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAA, 1693 DMAADDR(ed)); 1694 bus_space_write_2(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAC, 1695 (uint8_t *)end - (uint8_t *)start); 1696 bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM, 1697 ESO_IO_A2DMAM_DMAENB | ESO_IO_A2DMAM_AUTO); 1698 1699 /* Start DMA. */ 1700 a2c1 = eso_read_mixreg(sc, ESO_MIXREG_A2C1); 1701 a2c1 &= ~ESO_MIXREG_A2C1_RESV0; /* Paranoia? XXX bit 5 */ 1702 a2c1 |= ESO_MIXREG_A2C1_FIFOENB | ESO_MIXREG_A2C1_DMAENB | 1703 ESO_MIXREG_A2C1_AUTO; 1704 eso_write_mixreg(sc, ESO_MIXREG_A2C1, a2c1); 1705 1706 return 0; 1707 } 1708 1709 static int 1710 eso_trigger_input(void *hdl, void *start, void *end, int blksize, 1711 void (*intr)(void *), void *arg, const audio_params_t *param) 1712 { 1713 struct eso_softc *sc; 1714 struct eso_dma *ed; 1715 uint8_t actl, a1c1; 1716 1717 sc = hdl; 1718 DPRINTF(( 1719 "%s: trigger_input: start %p, end %p, blksize %d, intr %p(%p)\n", 1720 sc->sc_dev.dv_xname, start, end, blksize, intr, arg)); 1721 DPRINTF(("%s: param: rate %u, encoding %u, precision %u, channels %u\n", 1722 sc->sc_dev.dv_xname, param->sample_rate, param->encoding, 1723 param->precision, param->channels)); 1724 1725 /* 1726 * If we failed to configure the Audio 1 DMA controller, bail here 1727 * while retaining availability of the DAC direction (in Audio 2). 1728 */ 1729 if (!sc->sc_dmac_configured) 1730 return EIO; 1731 1732 /* Find DMA buffer. */ 1733 for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != start; 1734 ed = ed->ed_next) 1735 continue; 1736 if (ed == NULL) { 1737 printf("%s: trigger_output: bad addr %p\n", 1738 sc->sc_dev.dv_xname, start); 1739 return EINVAL; 1740 } 1741 DPRINTF(("%s: dmaaddr %lx\n", 1742 sc->sc_dev.dv_xname, (unsigned long)DMAADDR(ed))); 1743 1744 sc->sc_rintr = intr; 1745 sc->sc_rarg = arg; 1746 1747 /* Compute drain timeout. */ 1748 sc->sc_rdrain = (blksize * NBBY * hz) / 1749 (param->sample_rate * param->channels * 1750 param->precision) + 2; /* slop */ 1751 1752 /* Set up ADC DMA converter parameters. */ 1753 actl = eso_read_ctlreg(sc, ESO_CTLREG_ACTL); 1754 if (param->channels == 2) { 1755 actl &= ~ESO_CTLREG_ACTL_MONO; 1756 actl |= ESO_CTLREG_ACTL_STEREO; 1757 } else { 1758 actl &= ~ESO_CTLREG_ACTL_STEREO; 1759 actl |= ESO_CTLREG_ACTL_MONO; 1760 } 1761 eso_write_ctlreg(sc, ESO_CTLREG_ACTL, actl); 1762 1763 /* Set up Transfer Type: maybe move to attach time? */ 1764 eso_write_ctlreg(sc, ESO_CTLREG_A1TT, ESO_CTLREG_A1TT_DEMAND4); 1765 1766 /* DMA transfer count reload using 2's complement. */ 1767 blksize = -blksize; 1768 eso_write_ctlreg(sc, ESO_CTLREG_A1TCRLO, blksize & 0xff); 1769 eso_write_ctlreg(sc, ESO_CTLREG_A1TCRHI, blksize >> 8); 1770 1771 /* Set up and enable Audio 1 DMA FIFO. */ 1772 a1c1 = ESO_CTLREG_A1C1_RESV1 | ESO_CTLREG_A1C1_FIFOENB; 1773 if (param->precision == 16) 1774 a1c1 |= ESO_CTLREG_A1C1_16BIT; 1775 if (param->channels == 2) 1776 a1c1 |= ESO_CTLREG_A1C1_STEREO; 1777 else 1778 a1c1 |= ESO_CTLREG_A1C1_MONO; 1779 if (param->encoding == AUDIO_ENCODING_SLINEAR_BE || 1780 param->encoding == AUDIO_ENCODING_SLINEAR_LE) 1781 a1c1 |= ESO_CTLREG_A1C1_SIGNED; 1782 eso_write_ctlreg(sc, ESO_CTLREG_A1C1, a1c1); 1783 1784 /* Set up ADC IRQ/DRQ parameters. */ 1785 eso_write_ctlreg(sc, ESO_CTLREG_LAIC, 1786 ESO_CTLREG_LAIC_PINENB | ESO_CTLREG_LAIC_EXTENB); 1787 eso_write_ctlreg(sc, ESO_CTLREG_DRQCTL, 1788 ESO_CTLREG_DRQCTL_ENB1 | ESO_CTLREG_DRQCTL_EXTENB); 1789 1790 /* Set up and enable DMA controller. */ 1791 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_CLEAR, 0); 1792 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK, 1793 ESO_DMAC_MASK_MASK); 1794 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MODE, 1795 DMA37MD_WRITE | DMA37MD_LOOP | DMA37MD_DEMAND); 1796 bus_space_write_4(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_DMAA, 1797 DMAADDR(ed)); 1798 bus_space_write_2(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_DMAC, 1799 (uint8_t *)end - (uint8_t *)start - 1); 1800 bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK, 0); 1801 1802 /* Start DMA. */ 1803 eso_write_ctlreg(sc, ESO_CTLREG_A1C2, 1804 ESO_CTLREG_A1C2_DMAENB | ESO_CTLREG_A1C2_READ | 1805 ESO_CTLREG_A1C2_AUTO | ESO_CTLREG_A1C2_ADC); 1806 1807 return 0; 1808 } 1809 1810 /* 1811 * Mixer utility functions. 1812 */ 1813 static int 1814 eso_set_recsrc(struct eso_softc *sc, unsigned int recsrc) 1815 { 1816 mixer_devinfo_t di; 1817 int i; 1818 1819 di.index = ESO_RECORD_SOURCE; 1820 if (eso_query_devinfo(sc, &di) != 0) 1821 panic("eso_set_recsrc: eso_query_devinfo failed"); 1822 1823 for (i = 0; i < di.un.e.num_mem; i++) { 1824 if (recsrc == di.un.e.member[i].ord) { 1825 eso_write_mixreg(sc, ESO_MIXREG_ERS, recsrc); 1826 sc->sc_recsrc = recsrc; 1827 return 0; 1828 } 1829 } 1830 1831 return EINVAL; 1832 } 1833 1834 static int 1835 eso_set_monooutsrc(struct eso_softc *sc, unsigned int monooutsrc) 1836 { 1837 mixer_devinfo_t di; 1838 int i; 1839 uint8_t mpm; 1840 1841 di.index = ESO_MONOOUT_SOURCE; 1842 if (eso_query_devinfo(sc, &di) != 0) 1843 panic("eso_set_monooutsrc: eso_query_devinfo failed"); 1844 1845 for (i = 0; i < di.un.e.num_mem; i++) { 1846 if (monooutsrc == di.un.e.member[i].ord) { 1847 mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM); 1848 mpm &= ~ESO_MIXREG_MPM_MOMASK; 1849 mpm |= monooutsrc; 1850 eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm); 1851 sc->sc_monooutsrc = monooutsrc; 1852 return 0; 1853 } 1854 } 1855 1856 return EINVAL; 1857 } 1858 1859 static int 1860 eso_set_monoinbypass(struct eso_softc *sc, unsigned int monoinbypass) 1861 { 1862 mixer_devinfo_t di; 1863 int i; 1864 uint8_t mpm; 1865 1866 di.index = ESO_MONOIN_BYPASS; 1867 if (eso_query_devinfo(sc, &di) != 0) 1868 panic("eso_set_monoinbypass: eso_query_devinfo failed"); 1869 1870 for (i = 0; i < di.un.e.num_mem; i++) { 1871 if (monoinbypass == di.un.e.member[i].ord) { 1872 mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM); 1873 mpm &= ~(ESO_MIXREG_MPM_MOMASK | ESO_MIXREG_MPM_RESV0); 1874 mpm |= (monoinbypass ? ESO_MIXREG_MPM_MIBYPASS : 0); 1875 eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm); 1876 sc->sc_monoinbypass = monoinbypass; 1877 return 0; 1878 } 1879 } 1880 1881 return EINVAL; 1882 } 1883 1884 static int 1885 eso_set_preamp(struct eso_softc *sc, unsigned int preamp) 1886 { 1887 mixer_devinfo_t di; 1888 int i; 1889 uint8_t mpm; 1890 1891 di.index = ESO_MIC_PREAMP; 1892 if (eso_query_devinfo(sc, &di) != 0) 1893 panic("eso_set_preamp: eso_query_devinfo failed"); 1894 1895 for (i = 0; i < di.un.e.num_mem; i++) { 1896 if (preamp == di.un.e.member[i].ord) { 1897 mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM); 1898 mpm &= ~(ESO_MIXREG_MPM_PREAMP | ESO_MIXREG_MPM_RESV0); 1899 mpm |= (preamp ? ESO_MIXREG_MPM_PREAMP : 0); 1900 eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm); 1901 sc->sc_preamp = preamp; 1902 return 0; 1903 } 1904 } 1905 1906 return EINVAL; 1907 } 1908 1909 /* 1910 * Reload Master Volume and Mute values in softc from mixer; used when 1911 * those have previously been invalidated by use of hardware volume controls. 1912 */ 1913 static void 1914 eso_reload_master_vol(struct eso_softc *sc) 1915 { 1916 uint8_t mv; 1917 1918 mv = eso_read_mixreg(sc, ESO_MIXREG_LMVM); 1919 sc->sc_gain[ESO_MASTER_VOL][ESO_LEFT] = 1920 (mv & ~ESO_MIXREG_LMVM_MUTE) << 2; 1921 mv = eso_read_mixreg(sc, ESO_MIXREG_LMVM); 1922 sc->sc_gain[ESO_MASTER_VOL][ESO_RIGHT] = 1923 (mv & ~ESO_MIXREG_RMVM_MUTE) << 2; 1924 /* Currently both channels are muted simultaneously; either is OK. */ 1925 sc->sc_mvmute = (mv & ESO_MIXREG_RMVM_MUTE) != 0; 1926 } 1927 1928 static void 1929 eso_set_gain(struct eso_softc *sc, unsigned int port) 1930 { 1931 uint8_t mixreg, tmp; 1932 1933 switch (port) { 1934 case ESO_DAC_PLAY_VOL: 1935 mixreg = ESO_MIXREG_PVR_A2; 1936 break; 1937 case ESO_MIC_PLAY_VOL: 1938 mixreg = ESO_MIXREG_PVR_MIC; 1939 break; 1940 case ESO_LINE_PLAY_VOL: 1941 mixreg = ESO_MIXREG_PVR_LINE; 1942 break; 1943 case ESO_SYNTH_PLAY_VOL: 1944 mixreg = ESO_MIXREG_PVR_SYNTH; 1945 break; 1946 case ESO_CD_PLAY_VOL: 1947 mixreg = ESO_MIXREG_PVR_CD; 1948 break; 1949 case ESO_AUXB_PLAY_VOL: 1950 mixreg = ESO_MIXREG_PVR_AUXB; 1951 break; 1952 1953 case ESO_DAC_REC_VOL: 1954 mixreg = ESO_MIXREG_RVR_A2; 1955 break; 1956 case ESO_MIC_REC_VOL: 1957 mixreg = ESO_MIXREG_RVR_MIC; 1958 break; 1959 case ESO_LINE_REC_VOL: 1960 mixreg = ESO_MIXREG_RVR_LINE; 1961 break; 1962 case ESO_SYNTH_REC_VOL: 1963 mixreg = ESO_MIXREG_RVR_SYNTH; 1964 break; 1965 case ESO_CD_REC_VOL: 1966 mixreg = ESO_MIXREG_RVR_CD; 1967 break; 1968 case ESO_AUXB_REC_VOL: 1969 mixreg = ESO_MIXREG_RVR_AUXB; 1970 break; 1971 case ESO_MONO_PLAY_VOL: 1972 mixreg = ESO_MIXREG_PVR_MONO; 1973 break; 1974 case ESO_MONO_REC_VOL: 1975 mixreg = ESO_MIXREG_RVR_MONO; 1976 break; 1977 1978 case ESO_PCSPEAKER_VOL: 1979 /* Special case - only 3-bit, mono, and reserved bits. */ 1980 tmp = eso_read_mixreg(sc, ESO_MIXREG_PCSVR); 1981 tmp &= ESO_MIXREG_PCSVR_RESV; 1982 /* Map bits 7:5 -> 2:0. */ 1983 tmp |= (sc->sc_gain[port][ESO_LEFT] >> 5); 1984 eso_write_mixreg(sc, ESO_MIXREG_PCSVR, tmp); 1985 return; 1986 1987 case ESO_MASTER_VOL: 1988 /* Special case - separate regs, and 6-bit precision. */ 1989 /* Map bits 7:2 -> 5:0, reflect mute settings. */ 1990 eso_write_mixreg(sc, ESO_MIXREG_LMVM, 1991 (sc->sc_gain[port][ESO_LEFT] >> 2) | 1992 (sc->sc_mvmute ? ESO_MIXREG_LMVM_MUTE : 0x00)); 1993 eso_write_mixreg(sc, ESO_MIXREG_RMVM, 1994 (sc->sc_gain[port][ESO_RIGHT] >> 2) | 1995 (sc->sc_mvmute ? ESO_MIXREG_RMVM_MUTE : 0x00)); 1996 return; 1997 1998 case ESO_SPATIALIZER: 1999 /* Special case - only `mono', and higher precision. */ 2000 eso_write_mixreg(sc, ESO_MIXREG_SPATLVL, 2001 sc->sc_gain[port][ESO_LEFT]); 2002 return; 2003 2004 case ESO_RECORD_VOL: 2005 /* Very Special case, controller register. */ 2006 eso_write_ctlreg(sc, ESO_CTLREG_RECLVL,ESO_4BIT_GAIN_TO_STEREO( 2007 sc->sc_gain[port][ESO_LEFT], sc->sc_gain[port][ESO_RIGHT])); 2008 return; 2009 2010 default: 2011 #ifdef DIAGNOSTIC 2012 panic("eso_set_gain: bad port %u", port); 2013 /* NOTREACHED */ 2014 #else 2015 return; 2016 #endif 2017 } 2018 2019 eso_write_mixreg(sc, mixreg, ESO_4BIT_GAIN_TO_STEREO( 2020 sc->sc_gain[port][ESO_LEFT], sc->sc_gain[port][ESO_RIGHT])); 2021 } 2022