The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/pci/eso.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: dc58fc5e16aef5c077b3e941aa9bb817


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.