Home | History | Annotate | Line # | Download | only in pci
eap.c revision 1.5
      1 /*	$NetBSD: eap.c,v 1.5 1998/05/06 19:21:45 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author:      Lennart Augustsson <augustss (at) cs.chalmers.se>
      8  *
      9  * Debugging:   Andreas Gustafsson <gson (at) araneus.fi>
     10  *		Charles Hannum     <mycroft (at) netbsd.org>
     11  * Testing:     Chuck Cranor       <chuck (at) maria.wustl.edu>
     12  *              Phil Nelson        <phil (at) cs.wwu.edu>
     13  *
     14  * Redistribution and use in source and binary forms, with or without
     15  * modification, are permitted provided that the following conditions
     16  * are met:
     17  * 1. Redistributions of source code must retain the above copyright
     18  *    notice, this list of conditions and the following disclaimer.
     19  * 2. Redistributions in binary form must reproduce the above copyright
     20  *    notice, this list of conditions and the following disclaimer in the
     21  *    documentation and/or other materials provided with the distribution.
     22  * 3. All advertising materials mentioning features or use of this software
     23  *    must display the following acknowledgement:
     24  *        This product includes software developed by the NetBSD
     25  *        Foundation, Inc. and its contributors.
     26  * 4. Neither the name of The NetBSD Foundation nor the names of its
     27  *    contributors may be used to endorse or promote products derived
     28  *    from this software without specific prior written permission.
     29  *
     30  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     31  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     32  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     33  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     34  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     35  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     36  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     38  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     40  * POSSIBILITY OF SUCH DAMAGE.
     41  */
     42 
     43 /*
     44  * Ensoniq AudoiPCI ES1370 + AK4531 driver.
     45  * Data sheets can be found at
     46  * http://www.ensoniq.com/multimedia/semi_html/html/es1370.zip
     47  * and
     48  * http://206.214.38.151/pdf/4531.pdf
     49  */
     50 
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/kernel.h>
     54 #include <sys/malloc.h>
     55 #include <sys/device.h>
     56 
     57 #include <dev/pci/pcidevs.h>
     58 #include <dev/pci/pcivar.h>
     59 
     60 #include <sys/audioio.h>
     61 #include <dev/audio_if.h>
     62 #include <dev/mulaw.h>
     63 #include <dev/auconv.h>
     64 
     65 #include <machine/bus.h>
     66 
     67 /* NetBSD 1.3 backwards compatibility */
     68 #ifndef BUS_DMA_COHERENT
     69 #define BUS_DMA_COHERENT 0	/* XXX */
     70 struct        cfdriver eap_cd = {
     71       NULL, "eap", DV_DULL
     72 };
     73 #endif
     74 
     75 #define	PCI_CBIO		0x10
     76 
     77 #define EAP_ICSC		0x00    /* interrupt / chip select control */
     78 #define  EAP_SERR_DISABLE	0x00000001
     79 #define  EAP_CDC_EN		0x00000002
     80 #define  EAP_JYSTK_EN		0x00000004
     81 #define  EAP_UART_EN		0x00000008
     82 #define  EAP_ADC_EN		0x00000010
     83 #define  EAP_DAC2_EN		0x00000020
     84 #define  EAP_DAC1_EN		0x00000040
     85 #define  EAP_BREQ		0x00000080
     86 #define  EAP_XTCL0		0x00000100
     87 #define  EAP_M_CB		0x00000200
     88 #define  EAP_CCB_INTRM		0x00000400
     89 #define  EAP_DAC_SYNC		0x00000800
     90 #define  EAP_WTSRSEL		0x00003000
     91 #define   EAP_WTSRSEL_5		0x00000000
     92 #define   EAP_WTSRSEL_11	0x00001000
     93 #define   EAP_WTSRSEL_22	0x00002000
     94 #define   EAP_WTSRSEL_44	0x00003000
     95 #define  EAP_M_SBB		0x00004000
     96 #define  EAP_MSFMTSEL		0x00008000
     97 #define  EAP_SET_PCLKDIV(n)	(((n)&0x1fff)<<16)
     98 #define  EAP_GET_PCLKDIV(n)	(((n)>>16)&0x1fff)
     99 #define  EAP_PCLKBITS		0x1fff0000
    100 #define  EAP_XTCL1		0x40000000
    101 #define  EAP_ADC_STOP		0x80000000
    102 
    103 #define EAP_ICSS		0x04	/* interrupt / chip select status */
    104 #define  EAP_I_ADC		0x00000001
    105 #define  EAP_I_DAC2		0x00000002
    106 #define  EAP_I_DAC1		0x00000004
    107 #define  EAP_I_UART		0x00000008
    108 #define  EAP_I_MCCB		0x00000010
    109 #define  EAP_VC			0x00000060
    110 #define  EAP_CWRIP		0x00000100
    111 #define  EAP_CBUSY		0x00000200
    112 #define  EAP_CSTAT		0x00000400
    113 #define  EAP_INTR		0x80000000
    114 
    115 #define EAP_UART_DATA		0x08
    116 #define EAP_UART_STATUS		0x09
    117 #define EAP_UART_CONTROL	0x09
    118 #define EAP_MEMPAGE		0x0c
    119 #define EAP_CODEC		0x10
    120 #define  EAP_SET_CODEC(a,d)	(((a)<<8) | (d))
    121 
    122 #define EAP_SIC			0x20
    123 #define  EAP_P1_S_MB		0x00000001
    124 #define  EAP_P1_S_EB		0x00000002
    125 #define  EAP_P2_S_MB		0x00000004
    126 #define  EAP_P2_S_EB		0x00000008
    127 #define  EAP_R1_S_MB		0x00000010
    128 #define  EAP_R1_S_EB		0x00000020
    129 #define  EAP_R1P2_BITS		0x0000003c
    130 #define  EAP_P2_DAC_SEN		0x00000040
    131 #define  EAP_P1_SCT_RLD		0x00000080
    132 #define  EAP_P1_INTR_EN		0x00000100
    133 #define  EAP_P2_INTR_EN		0x00000200
    134 #define  EAP_R1_INTR_EN		0x00000400
    135 #define  EAP_P1_PAUSE		0x00000800
    136 #define  EAP_P2_PAUSE		0x00001000
    137 #define  EAP_P1_LOOP_SEL	0x00002000
    138 #define  EAP_P2_LOOP_SEL	0x00004000
    139 #define  EAP_R1_LOOP_SEL	0x00008000
    140 #define  EAP_SET_P2_ST_INC(i)	((i) << 16)
    141 #define  EAP_SET_P2_END_INC(i)	((i) << 19)
    142 #define  EAP_INC_BITS		0x003f0000
    143 
    144 #define EAP_DAC1_CSR		0x24
    145 #define EAP_DAC2_CSR		0x28
    146 #define EAP_ADC_CSR		0x2c
    147 #define  EAP_GET_CURRSAMP(r)	((r) >> 16)
    148 
    149 #define EAP_DAC_PAGE		0xc
    150 #define EAP_ADC_PAGE		0xd
    151 #define EAP_UART_PAGE1		0xe
    152 #define EAP_UART_PAGE2		0xf
    153 
    154 #define EAP_DAC1_ADDR		0x30
    155 #define EAP_DAC1_SIZE		0x34
    156 #define EAP_DAC2_ADDR		0x38
    157 #define EAP_DAC2_SIZE		0x3c
    158 #define EAP_ADC_ADDR		0x30
    159 #define EAP_ADC_SIZE		0x34
    160 #define  EAP_SET_SIZE(c,s)	(((c)<<16) | (s))
    161 
    162 #define EAP_XTAL_FREQ 1411200 /* 22.5792 / 16 MHz */
    163 
    164 /* AK4531 registers */
    165 #define AK_MASTER_L		0x00
    166 #define AK_MASTER_R		0x01
    167 #define AK_VOICE_L		0x02
    168 #define AK_VOICE_R		0x03
    169 #define AK_FM_L			0x04
    170 #define AK_FM_R			0x05
    171 #define AK_CD_L			0x06
    172 #define AK_CD_R			0x07
    173 #define AK_LINE_L		0x08
    174 #define AK_LINE_R		0x09
    175 #define AK_AUX_L		0x0a
    176 #define AK_AUX_R		0x0b
    177 #define AK_MONO1		0x0c
    178 #define AK_MONO2		0x0d
    179 #define AK_MIC			0x0e
    180 #define AK_MONO			0x0f
    181 #define AK_OUT_MIXER1		0x10
    182 #define  AK_M_FM_L		0x40
    183 #define  AK_M_FM_R		0x20
    184 #define  AK_M_LINE_L		0x10
    185 #define  AK_M_LINE_R		0x08
    186 #define  AK_M_CD_L		0x04
    187 #define  AK_M_CD_R		0x02
    188 #define  AK_M_MIC		0x01
    189 #define AK_OUT_MIXER2		0x11
    190 #define  AK_M_AUX_L		0x20
    191 #define  AK_M_AUX_R		0x10
    192 #define  AK_M_VOICE_L		0x08
    193 #define  AK_M_VOICE_R		0x04
    194 #define  AK_M_MONO2		0x02
    195 #define  AK_M_MONO1		0x01
    196 #define AK_IN_MIXER1_L		0x12
    197 #define AK_IN_MIXER1_R		0x13
    198 #define AK_IN_MIXER2_L		0x14
    199 #define AK_IN_MIXER2_R		0x15
    200 #define  AK_M_TMIC		0x80
    201 #define  AK_M_TMONO1		0x40
    202 #define  AK_M_TMONO2		0x20
    203 #define  AK_M2_AUX_L		0x10
    204 #define  AK_M2_AUX_R		0x08
    205 #define  AK_M_VOICE		0x04
    206 #define  AK_M2_MONO2		0x02
    207 #define  AK_M2_MONO1		0x01
    208 #define AK_RESET		0x16
    209 #define  AK_PD			0x02
    210 #define  AK_NRST		0x01
    211 #define AK_CS			0x17
    212 #define AK_ADSEL		0x18
    213 #define AK_MGAIN		0x19
    214 
    215 #define AK_NPORTS 16
    216 
    217 #define VOL_TO_ATT5(v) (0x1f - ((v) >> 3))
    218 #define VOL_TO_GAIN5(v) VOL_TO_ATT5(v)
    219 #define ATT5_TO_VOL(v) ((0x1f - (v)) << 3)
    220 #define GAIN5_TO_VOL(v) ATT5_TO_VOL(v)
    221 #define VOL_0DB 200
    222 
    223 #define EAP_MASTER_VOL		0
    224 #define EAP_VOICE_VOL		1
    225 #define EAP_FM_VOL		2
    226 #define EAP_CD_VOL		3
    227 #define EAP_LINE_VOL		4
    228 #define EAP_AUX_VOL		5
    229 #define EAP_MIC_VOL		6
    230 #define	EAP_RECORD_SOURCE 	7
    231 #define EAP_OUTPUT_CLASS	8
    232 #define EAP_RECORD_CLASS	9
    233 #define EAP_INPUT_CLASS		10
    234 
    235 #define EAP_NDEVS		11
    236 
    237 
    238 #ifdef AUDIO_DEBUG
    239 #define DPRINTF(x)	if (eapdebug) printf x
    240 #define DPRINTFN(n,x)	if (eapdebug>(n)) printf x
    241 int	eapdebug = 0;
    242 #else
    243 #define DPRINTF(x)
    244 #define DPRINTFN(n,x)
    245 #endif
    246 
    247 #ifdef __BROKEN_INDIRECT_CONFIG
    248 int	eap_match __P((struct device *, void *, void *));
    249 #else
    250 int	eap_match __P((struct device *, struct cfdata *, void *));
    251 #endif
    252 void	eap_attach __P((struct device *, struct device *, void *));
    253 int	eap_intr __P((void *));
    254 
    255 struct eap_dma {
    256 	bus_dmamap_t map;
    257         caddr_t addr;
    258         bus_dma_segment_t segs[1];
    259         int nsegs;
    260         size_t size;
    261         struct eap_dma *next;
    262 };
    263 #define DMAADDR(map) ((map)->segs[0].ds_addr)
    264 #define KERNADDR(map) ((void *)((map)->addr))
    265 
    266 struct eap_softc {
    267 	struct device sc_dev;		/* base device */
    268 	void *sc_ih;			/* interrupt vectoring */
    269 	bus_space_tag_t iot;
    270 	bus_space_handle_t ioh;
    271 	bus_dma_tag_t sc_dmatag;	/* DMA tag */
    272 
    273         struct eap_dma *sc_dmas;
    274 
    275 	void	(*sc_pintr)(void *);	/* dma completion intr handler */
    276 	void	*sc_parg;		/* arg for sc_intr() */
    277 	char	sc_prun;
    278 
    279 	void	(*sc_rintr)(void *);	/* dma completion intr handler */
    280 	void	*sc_rarg;		/* arg for sc_intr() */
    281 	char	sc_rrun;
    282 
    283 	int	sc_sampsize;		/* bytes / sample */
    284 
    285 	u_char	sc_port[AK_NPORTS];	/* mirror of the hardware setting */
    286 	u_int	sc_record_source;	/* recording source mask */
    287 };
    288 
    289 int	eap_allocmem __P((struct eap_softc *, size_t, size_t, struct eap_dma *));
    290 int	eap_freemem __P((struct eap_softc *, struct eap_dma *));
    291 
    292 #define EWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
    293 #define EWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
    294 #define EREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
    295 #define EREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
    296 
    297 struct cfattach eap_ca = {
    298 	sizeof(struct eap_softc), eap_match, eap_attach
    299 };
    300 
    301 int	eap_open __P((void *, int));
    302 void	eap_close __P((void *));
    303 int	eap_query_encoding __P((void *, struct audio_encoding *));
    304 int	eap_set_params __P((void *, int, int, struct audio_params *, struct audio_params *));
    305 int	eap_round_blocksize __P((void *, int));
    306 int	eap_dma_init_output __P((void *, void *, int));
    307 int	eap_dma_init_input __P((void *, void *, int));
    308 int	eap_dma_output __P((void *, void *, int, void (*)(void *), void*));
    309 int	eap_dma_input __P((void *, void *, int, void (*)(void *), void*));
    310 int	eap_halt_in_dma __P((void *));
    311 int	eap_halt_out_dma __P((void *));
    312 int	eap_getdev __P((void *, struct audio_device *));
    313 int	eap_mixer_set_port __P((void *, mixer_ctrl_t *));
    314 int	eap_mixer_get_port __P((void *, mixer_ctrl_t *));
    315 int	eap_query_devinfo __P((void *, mixer_devinfo_t *));
    316 void   *eap_malloc __P((void *, u_long, int, int));
    317 void	eap_free __P((void *, void *, int));
    318 u_long	eap_round __P((void *, u_long));
    319 int	eap_mappage __P((void *, void *, int, int));
    320 int	eap_get_props __P((void *));
    321 void	eap_write_codec __P((struct eap_softc *sc, int a, int d));
    322 void	eap_set_mixer __P((struct eap_softc *sc, int a, int d));
    323 
    324 struct audio_hw_if eap_hw_if = {
    325 	eap_open,
    326 	eap_close,
    327 	NULL,
    328 	eap_query_encoding,
    329 	eap_set_params,
    330 	eap_round_blocksize,
    331 	NULL,
    332 	eap_dma_init_output,
    333 	eap_dma_init_input,
    334 	eap_dma_output,
    335 	eap_dma_input,
    336 	eap_halt_out_dma,
    337 	eap_halt_in_dma,
    338 	NULL,
    339 	eap_getdev,
    340 	NULL,
    341 	eap_mixer_set_port,
    342 	eap_mixer_get_port,
    343 	eap_query_devinfo,
    344 	eap_malloc,
    345 	eap_free,
    346 	eap_round,
    347 	eap_mappage,
    348 	eap_get_props,
    349 };
    350 
    351 struct audio_device eap_device = {
    352 	"Ensoniq AudioPCI",
    353 	"",
    354 	"eap"
    355 };
    356 
    357 int
    358 eap_match(parent, match, aux)
    359 	struct device *parent;
    360 #ifdef __BROKEN_INDIRECT_CONFIG
    361 	void *match;
    362 #else
    363 	struct cfdata *match;
    364 #endif
    365 	void *aux;
    366 {
    367 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    368 
    369 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_ENSONIQ)
    370 		return (0);
    371 	if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_ENSONIQ_AUDIOPCI)
    372 		return (0);
    373 
    374 	return (1);
    375 }
    376 
    377 void
    378 eap_write_codec(sc, a, d)
    379 	struct eap_softc *sc;
    380 	int a, d;
    381 {
    382 	int icss;
    383 
    384 	do {
    385 	        icss = EREAD4(sc, EAP_ICSS);
    386 		DPRINTFN(5,("eap: codec %d prog: icss=0x%08x\n", a, icss));
    387 	} while(icss & EAP_CWRIP);
    388 	EWRITE4(sc, EAP_CODEC, EAP_SET_CODEC(a, d));
    389 }
    390 
    391 void
    392 eap_attach(parent, self, aux)
    393 	struct device *parent;
    394 	struct device *self;
    395 	void *aux;
    396 {
    397 	struct eap_softc *sc = (struct eap_softc *)self;
    398 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    399 	pci_chipset_tag_t pc = pa->pa_pc;
    400 	char const *intrstr;
    401 	pci_intr_handle_t ih;
    402 	pcireg_t csr;
    403 	char devinfo[256];
    404 	mixer_ctrl_t ctl;
    405 
    406 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    407 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    408 
    409 	/* Map I/O register */
    410 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    411 	      &sc->iot, &sc->ioh, NULL, NULL)) {
    412 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    413 		return;
    414 	}
    415 
    416 	sc->sc_dmatag = pa->pa_dmat;
    417 
    418 	/* Enable the device. */
    419 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    420 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    421 		       csr | PCI_COMMAND_MASTER_ENABLE);
    422 
    423 	/* Map and establish the interrupt. */
    424 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    425 	    pa->pa_intrline, &ih)) {
    426 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    427 		return;
    428 	}
    429 	intrstr = pci_intr_string(pc, ih);
    430 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, eap_intr, sc);
    431 	if (sc->sc_ih == NULL) {
    432 		printf("%s: couldn't establish interrupt",
    433 		    sc->sc_dev.dv_xname);
    434 		if (intrstr != NULL)
    435 			printf(" at %s", intrstr);
    436 		printf("\n");
    437 		return;
    438 	}
    439 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    440 
    441 	/* Enable interrupts and looping mode. */
    442         EWRITE4(sc, EAP_SIC, EAP_P2_INTR_EN | EAP_R1_INTR_EN);
    443         EWRITE4(sc, EAP_ICSC, EAP_CDC_EN); /* enable the parts we need */
    444 
    445 	eap_write_codec(sc, AK_RESET, AK_PD); /* reset codec */
    446 	eap_write_codec(sc, AK_RESET, AK_PD | AK_NRST);	/* normal operation */
    447 	eap_write_codec(sc, AK_CS, 0x0); /* select codec clocks */
    448 	/* Enable all relevant mixer switches. */
    449 	eap_write_codec(sc, AK_OUT_MIXER1,
    450 			AK_M_FM_L | AK_M_FM_R |
    451 			AK_M_LINE_L | AK_M_LINE_R |
    452 			AK_M_CD_L | AK_M_CD_R);
    453 	eap_write_codec(sc, AK_OUT_MIXER2,
    454 			AK_M_AUX_L | AK_M_AUX_R |
    455 			AK_M_VOICE_L | AK_M_VOICE_R |
    456 			AK_M_MONO2 | AK_M_MONO1);
    457 	ctl.type = AUDIO_MIXER_VALUE;
    458 	ctl.un.value.num_channels = 1;
    459 	for (ctl.dev = EAP_MASTER_VOL; ctl.dev < EAP_MIC_VOL; ctl.dev++) {
    460 		ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = VOL_0DB;
    461 		eap_mixer_set_port(sc, &ctl);
    462 	}
    463 	ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = 0;
    464 	eap_mixer_set_port(sc, &ctl); /* set the mic to 0 */
    465 	ctl.dev = EAP_RECORD_SOURCE;
    466 	ctl.type = AUDIO_MIXER_SET;
    467 	ctl.un.mask = 1 << EAP_MIC_VOL;
    468 	eap_mixer_set_port(sc, &ctl);
    469 
    470         audio_attach_mi(&eap_hw_if, 0, sc, &sc->sc_dev);
    471 }
    472 
    473 int
    474 eap_intr(p)
    475 	void *p;
    476 {
    477 	struct eap_softc *sc = p;
    478 	u_int32_t intr, sic;
    479 
    480         intr = EREAD4(sc, EAP_ICSS);
    481         if (!(intr & EAP_INTR))
    482         	return (0);
    483 	sic = EREAD4(sc, EAP_SIC);
    484 	DPRINTFN(5, ("eap_intr: ICSS=0x%08x, SIC=0x%08x\n", intr, sic));
    485         if (intr & EAP_I_ADC) {
    486 		EWRITE4(sc, EAP_SIC, sic & ~EAP_R1_INTR_EN);
    487 		EWRITE4(sc, EAP_SIC, sic);
    488                 if (sc->sc_rintr)
    489 	        	sc->sc_rintr(sc->sc_rarg);
    490         }
    491         if (intr & EAP_I_DAC2) {
    492 		EWRITE4(sc, EAP_SIC, sic & ~EAP_P2_INTR_EN);
    493 		EWRITE4(sc, EAP_SIC, sic);
    494                 if (sc->sc_pintr)
    495 	        	sc->sc_pintr(sc->sc_parg);
    496         }
    497 	return (1);
    498 }
    499 
    500 int
    501 eap_allocmem(sc, size, align, p)
    502 	struct eap_softc *sc;
    503 	size_t size;
    504 	size_t align;
    505         struct eap_dma *p;
    506 {
    507 	int error;
    508 
    509 	p->size = size;
    510 	error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
    511 				 p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
    512 				 &p->nsegs, BUS_DMA_NOWAIT);
    513 	if (error)
    514 		return (error);
    515 
    516 	error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
    517 			       &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    518 	if (error)
    519 		goto free;
    520 
    521 	error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
    522 				  0, BUS_DMA_NOWAIT, &p->map);
    523 	if (error)
    524 		goto unmap;
    525 
    526 	error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
    527 				BUS_DMA_NOWAIT);
    528 	if (error)
    529 		goto destroy;
    530 	return (0);
    531 
    532 destroy:
    533 	bus_dmamap_destroy(sc->sc_dmatag, p->map);
    534 unmap:
    535 	bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
    536 free:
    537 	bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
    538 	return (error);
    539 }
    540 
    541 int
    542 eap_freemem(sc, p)
    543 	struct eap_softc *sc;
    544         struct eap_dma *p;
    545 {
    546 	bus_dmamap_unload(sc->sc_dmatag, p->map);
    547 	bus_dmamap_destroy(sc->sc_dmatag, p->map);
    548 	bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
    549 	bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
    550 	return (0);
    551 }
    552 
    553 int
    554 eap_open(addr, flags)
    555 	void *addr;
    556 	int flags;
    557 {
    558 	struct eap_softc *sc = addr;
    559 
    560         DPRINTF(("eap_open: sc=%p\n", sc));
    561 
    562         sc->sc_pintr = 0;
    563         sc->sc_rintr = 0;
    564 
    565         return (0);
    566 }
    567 
    568 /*
    569  * Close function is called at splaudio().
    570  */
    571 void
    572 eap_close(addr)
    573 	void *addr;
    574 {
    575 	struct eap_softc *sc = addr;
    576 
    577         eap_halt_in_dma(sc);
    578         eap_halt_out_dma(sc);
    579 
    580         sc->sc_pintr = 0;
    581         sc->sc_rintr = 0;
    582 }
    583 
    584 int
    585 eap_query_encoding(addr, fp)
    586 	void *addr;
    587 	struct audio_encoding *fp;
    588 {
    589 	switch (fp->index) {
    590 	case 0:
    591 		strcpy(fp->name, AudioEulinear);
    592 		fp->encoding = AUDIO_ENCODING_ULINEAR;
    593 		fp->precision = 8;
    594 		fp->flags = 0;
    595 		return (0);
    596 	case 1:
    597 		strcpy(fp->name, AudioEmulaw);
    598 		fp->encoding = AUDIO_ENCODING_ULAW;
    599 		fp->precision = 8;
    600 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    601 		return (0);
    602 	case 2:
    603 		strcpy(fp->name, AudioEalaw);
    604 		fp->encoding = AUDIO_ENCODING_ALAW;
    605 		fp->precision = 8;
    606 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    607 		return (0);
    608 	case 3:
    609 		strcpy(fp->name, AudioEslinear);
    610 		fp->encoding = AUDIO_ENCODING_SLINEAR;
    611 		fp->precision = 8;
    612 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    613 		return (0);
    614         case 4:
    615 		strcpy(fp->name, AudioEslinear_le);
    616 		fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
    617 		fp->precision = 16;
    618 		fp->flags = 0;
    619 		return (0);
    620 	case 5:
    621 		strcpy(fp->name, AudioEulinear_le);
    622 		fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
    623 		fp->precision = 16;
    624 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    625 		return (0);
    626 	case 6:
    627 		strcpy(fp->name, AudioEslinear_be);
    628 		fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
    629 		fp->precision = 16;
    630 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    631 		return (0);
    632 	case 7:
    633 		strcpy(fp->name, AudioEulinear_be);
    634 		fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
    635 		fp->precision = 16;
    636 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    637 		return (0);
    638 	default:
    639 		return (EINVAL);
    640 	}
    641 }
    642 
    643 int
    644 eap_set_params(addr, setmode, usemode, p, r)
    645 	void *addr;
    646 	int setmode, usemode;
    647 	struct audio_params *p, *r;
    648 {
    649 	struct eap_softc *sc = addr;
    650 	void (*pswcode) __P((void *, u_char *buf, int cnt));
    651 	void (*rswcode) __P((void *, u_char *buf, int cnt));
    652         u_int32_t mode, div;
    653 
    654 
    655         pswcode = rswcode = 0;
    656         switch (p->encoding) {
    657         case AUDIO_ENCODING_SLINEAR_BE:
    658         	if (p->precision == 16)
    659                 	rswcode = pswcode = swap_bytes;
    660 		else
    661 			pswcode = rswcode = change_sign8;
    662 		break;
    663         case AUDIO_ENCODING_SLINEAR_LE:
    664         	if (p->precision != 16)
    665 			pswcode = rswcode = change_sign8;
    666         	break;
    667         case AUDIO_ENCODING_ULINEAR_BE:
    668         	if (p->precision == 16) {
    669 			pswcode = swap_bytes_change_sign16;
    670 			rswcode = change_sign16_swap_bytes;
    671 		}
    672 		break;
    673         case AUDIO_ENCODING_ULINEAR_LE:
    674         	if (p->precision == 16)
    675 			pswcode = rswcode = change_sign16;
    676         	break;
    677         case AUDIO_ENCODING_ULAW:
    678         	pswcode = mulaw_to_ulinear8;
    679                 rswcode = ulinear8_to_mulaw;
    680                 break;
    681         case AUDIO_ENCODING_ALAW:
    682                 pswcode = alaw_to_ulinear8;
    683                 rswcode = ulinear8_to_alaw;
    684                 break;
    685         default:
    686         	return (EINVAL);
    687         }
    688 	if (p->precision == 16)
    689 		mode = EAP_P2_S_EB | EAP_R1_S_EB;
    690 	else
    691 		mode = 0;
    692         if (p->channels == 2)
    693         	mode |= EAP_P2_S_MB | EAP_R1_S_MB;
    694 	else if (p->channels != 1)
    695 		return (EINVAL);
    696         if (p->sample_rate < 4000 || p->sample_rate > 50000)
    697         	return (EINVAL);
    698 
    699 	sc->sc_sampsize = p->precision / 8 * p->channels; /* bytes / sample */
    700         p->sw_code = pswcode;
    701         r->sw_code = rswcode;
    702 
    703         /* Set the encoding */
    704         mode |= EREAD4(sc, EAP_SIC) & ~(EAP_R1P2_BITS | EAP_INC_BITS);
    705 	mode |= EAP_SET_P2_ST_INC(0) | EAP_SET_P2_END_INC(p->precision / 8);
    706         EWRITE4(sc, EAP_SIC, mode);
    707 	DPRINTFN(2, ("eap_set_params: set SIC = 0x%08x\n", mode));
    708 
    709         /* Set the speed */
    710 	DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n",
    711 		     EREAD4(sc, EAP_ICSC)));
    712 	div = EREAD4(sc, EAP_ICSC) & ~EAP_PCLKBITS;
    713         div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ / p->sample_rate - 2);
    714 	div |= EAP_CCB_INTRM;
    715         EWRITE4(sc, EAP_ICSC, div);
    716 	DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div));
    717 
    718         return (0);
    719 }
    720 
    721 int
    722 eap_round_blocksize(addr, blk)
    723 	void *addr;
    724 	int blk;
    725 {
    726 	return (blk & -16);	/* keep good alignment */
    727 }
    728 
    729 int
    730 eap_dma_init_input(addr, buf, cc)
    731 	void *addr;
    732 	void *buf;
    733 	int cc;
    734 {
    735 	struct eap_softc *sc = addr;
    736 	struct eap_dma *p;
    737 
    738 	DPRINTF(("eap_dma_init_input: dma start loop input addr=%p cc=%d\n",
    739 		 buf, cc));
    740         for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
    741 		;
    742 	if (!p) {
    743 		printf("eap_dma_init_input: bad addr %p\n", buf);
    744 		return (EINVAL);
    745 	}
    746 	EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
    747 	EWRITE4(sc, EAP_ADC_ADDR, DMAADDR(p));
    748 	EWRITE4(sc, EAP_ADC_SIZE, EAP_SET_SIZE(0, cc / 4 - 1));
    749 	DPRINTF(("eap_dma_init_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
    750 		 (int)DMAADDR(p), EAP_SET_SIZE(0, cc / 4 - 1)));
    751 	return (0);
    752 }
    753 
    754 int
    755 eap_dma_init_output(addr, buf, cc)
    756 	void *addr;
    757 	void *buf;
    758 	int cc;
    759 {
    760 	struct eap_softc *sc = addr;
    761 	struct eap_dma *p;
    762 
    763 	DPRINTF(("eap: dma start loop output buf=%p cc=%d\n", buf, cc));
    764         for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
    765 		;
    766 	if (!p) {
    767 		printf("eap_dma_init_output: bad addr %p\n", buf);
    768 		return (EINVAL);
    769 	}
    770 	EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
    771 	EWRITE4(sc, EAP_DAC2_ADDR, DMAADDR(p));
    772 	EWRITE4(sc, EAP_DAC2_SIZE, EAP_SET_SIZE(0, cc / 4 - 1));
    773 	DPRINTF(("eap_dma_init_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
    774 		 (int)DMAADDR(p), EAP_SET_SIZE(0, cc / 4 - 1)));
    775 	return (0);
    776 }
    777 
    778 int
    779 eap_dma_output(addr, p, cc, intr, arg)
    780 	void *addr;
    781 	void *p;
    782 	int cc;
    783 	void (*intr) __P((void *));
    784 	void *arg;
    785 {
    786 	struct eap_softc *sc = addr;
    787 	u_int32_t mode;
    788 
    789 	DPRINTFN(sc->sc_prun ? 5 : 1,
    790                  ("eap_dma_output: sc=%p buf=%p cc=%d intr=%p(%p)\n",
    791                   addr, p, cc, intr, arg));
    792 	sc->sc_pintr = intr;
    793 	sc->sc_parg = arg;
    794 	if (!sc->sc_prun) {
    795 #if defined(DIAGNOSTIC) || defined(AUDIO_DEBUG)
    796 	        if (sc->sc_sampsize == 0) {
    797         		printf("eap_dma_output: sampsize == 0\n");
    798                         return EINVAL;
    799                 }
    800 #endif
    801 		EWRITE2(sc, EAP_DAC2_CSR, cc / sc->sc_sampsize - 1);
    802 		DPRINTFN(1, ("eap_dma_output: set DAC2_CSR = %d\n",
    803 			     cc / sc->sc_sampsize - 1));
    804 		DPRINTFN(1, ("eap_dma_output: old ICSC = 0x%08x\n",
    805 			     EREAD4(sc, EAP_ICSC)));
    806 		mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
    807 		EWRITE4(sc, EAP_ICSC, mode);
    808 		mode |= EAP_DAC2_EN;
    809 		EWRITE4(sc, EAP_ICSC, mode);
    810 		DPRINTFN(1, ("eap_dma_output: set ICSC = 0x%08x\n", mode));
    811 		sc->sc_prun = 1;
    812 	}
    813         return (0);
    814 }
    815 
    816 int
    817 eap_dma_input(addr, p, cc, intr, arg)
    818 	void *addr;
    819 	void *p;
    820 	int cc;
    821 	void (*intr) __P((void *));
    822 	void *arg;
    823 {
    824 	struct eap_softc *sc = addr;
    825 	u_int32_t mode;
    826 
    827 	DPRINTFN(1, ("eap_dma_input: sc=%p buf=%p cc=%d intr=%p(%p)\n",
    828 		     addr, p, cc, intr, arg));
    829 	sc->sc_rintr = intr;
    830 	sc->sc_rarg = arg;
    831 	if (!sc->sc_rrun) {
    832 #if defined(DIAGNOSTIC) || defined(AUDIO_DEBUG)
    833 	        if (sc->sc_sampsize == 0) {
    834         		printf("eap_dma_input: sampsize == 0\n");
    835                         return EINVAL;
    836                 }
    837 #endif
    838 		EWRITE2(sc, EAP_ADC_CSR, cc / sc->sc_sampsize - 1);
    839 		mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
    840 		EWRITE4(sc, EAP_ICSC, mode);
    841 		mode |= EAP_ADC_EN;
    842 		EWRITE4(sc, EAP_ICSC, mode);
    843 		DPRINTFN(1, ("eap_dma_input: set ICSC = 0x%08x\n", mode));
    844 		sc->sc_rrun = 1;
    845 	}
    846         return (0);
    847 }
    848 
    849 int
    850 eap_halt_out_dma(addr)
    851 	void *addr;
    852 {
    853 	struct eap_softc *sc = addr;
    854 	u_int32_t mode;
    855 
    856         DPRINTF(("eap: eap_halt_out_dma\n"));
    857 	mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
    858 	EWRITE4(sc, EAP_ICSC, mode);
    859 	sc->sc_prun = 0;
    860         return (0);
    861 }
    862 
    863 int
    864 eap_halt_in_dma(addr)
    865 	void *addr;
    866 {
    867 	struct eap_softc *sc = addr;
    868 	u_int32_t mode;
    869 
    870         DPRINTF(("eap: eap_halt_in_dma\n"));
    871 	mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
    872 	EWRITE4(sc, EAP_ICSC, mode);
    873 	sc->sc_rrun = 0;
    874         return (0);
    875 }
    876 
    877 int
    878 eap_getdev(addr, retp)
    879 	void *addr;
    880         struct audio_device *retp;
    881 {
    882 	*retp = eap_device;
    883         return (0);
    884 }
    885 
    886 void
    887 eap_set_mixer(sc, a, d)
    888 	struct eap_softc *sc;
    889         int a, d;
    890 {
    891 	eap_write_codec(sc, a, d);
    892         DPRINTFN(1, ("eap_mixer_set_port port 0x%02x = 0x%02x\n", a, d));
    893 }
    894 
    895 
    896 int
    897 eap_mixer_set_port(addr, cp)
    898 	void *addr;
    899 	mixer_ctrl_t *cp;
    900 {
    901 	struct eap_softc *sc = addr;
    902 	int lval, rval, l, r, la, ra;
    903 	int l1, r1, l2, r2, m;
    904 
    905 	if (cp->dev == EAP_RECORD_SOURCE) {
    906 		if (cp->type != AUDIO_MIXER_SET)
    907 			return (EINVAL);
    908 		m = sc->sc_record_source = cp->un.mask;
    909 		l1 = l2 = r1 = r2 = 0;
    910 		if (m & (1 << EAP_VOICE_VOL))
    911 			l2 |= AK_M_VOICE_L, r2 |= AK_M_VOICE_R;
    912 		if (m & (1 << EAP_FM_VOL))
    913 			l1 |= AK_M_FM_L, r1 |= AK_M_FM_R;
    914 		if (m & (1 << EAP_CD_VOL))
    915 			l1 |= AK_M_CD_L, r1 |= AK_M_CD_R;
    916 		if (m & (1 << EAP_LINE_VOL))
    917 			l1 |= AK_M_LINE_L, r1 |= AK_M_LINE_R;
    918 		if (m & (1 << EAP_AUX_VOL))
    919 			l2 |= AK_M_AUX_L, r2 |= AK_M_AUX_R;
    920 		if (m & (1 << EAP_MIC_VOL))
    921 			l2 |= AK_M_TMIC, r2 |= AK_M_TMIC;
    922 		eap_set_mixer(sc, AK_IN_MIXER1_L, l1);
    923 		eap_set_mixer(sc, AK_IN_MIXER1_R, r1);
    924 		eap_set_mixer(sc, AK_IN_MIXER2_L, l2);
    925 		eap_set_mixer(sc, AK_IN_MIXER2_R, r2);
    926 		return (0);
    927 	}
    928 	if (cp->type != AUDIO_MIXER_VALUE)
    929 		return (EINVAL);
    930 	if (cp->un.value.num_channels == 1)
    931 		lval = rval = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    932 	else if (cp->un.value.num_channels == 2) {
    933 		lval = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
    934 		rval = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
    935 	} else
    936 		return (EINVAL);
    937 	ra = -1;
    938 	switch (cp->dev) {
    939 	case EAP_MASTER_VOL:
    940 		l = VOL_TO_ATT5(lval);
    941 		r = VOL_TO_ATT5(rval);
    942 		la = AK_MASTER_L;
    943 		ra = AK_MASTER_R;
    944 		break;
    945 	case EAP_MIC_VOL:
    946 		if (cp->un.value.num_channels != 1)
    947 			return (EINVAL);
    948 		la = AK_MIC;
    949 		goto lr;
    950 	case EAP_VOICE_VOL:
    951 		la = AK_VOICE_L;
    952 		ra = AK_VOICE_R;
    953 		goto lr;
    954 	case EAP_FM_VOL:
    955 		la = AK_FM_L;
    956 		ra = AK_FM_R;
    957 		goto lr;
    958 	case EAP_CD_VOL:
    959 		la = AK_CD_L;
    960 		ra = AK_CD_R;
    961 		goto lr;
    962 	case EAP_LINE_VOL:
    963 		la = AK_LINE_L;
    964 		ra = AK_LINE_R;
    965 		goto lr;
    966 	case EAP_AUX_VOL:
    967 		la = AK_AUX_L;
    968 		ra = AK_AUX_R;
    969 	lr:
    970 		l = VOL_TO_GAIN5(lval);
    971 		r = VOL_TO_GAIN5(rval);
    972 		break;
    973 	default:
    974 		return (EINVAL);
    975 	}
    976 	eap_set_mixer(sc, la, l);
    977 	sc->sc_port[la] = l;
    978 	if (ra >= 0) {
    979 		eap_set_mixer(sc, ra, r);
    980 		sc->sc_port[ra] = r;
    981 	}
    982 	return (0);
    983 }
    984 
    985 int
    986 eap_mixer_get_port(addr, cp)
    987 	void *addr;
    988 	mixer_ctrl_t *cp;
    989 {
    990 	struct eap_softc *sc = addr;
    991 	int la, ra, l, r;
    992 
    993 	switch (cp->dev) {
    994 	case EAP_RECORD_SOURCE:
    995 		cp->un.mask = sc->sc_record_source;
    996 		return (0);
    997 	case EAP_MASTER_VOL:
    998 		l = ATT5_TO_VOL(sc->sc_port[AK_MASTER_L]);
    999 		r = ATT5_TO_VOL(sc->sc_port[AK_MASTER_R]);
   1000 		break;
   1001 	case EAP_MIC_VOL:
   1002 		if (cp->un.value.num_channels != 1)
   1003 			return (EINVAL);
   1004 		la = ra = AK_MIC;
   1005 		goto lr;
   1006 	case EAP_VOICE_VOL:
   1007 		la = AK_VOICE_L;
   1008 		ra = AK_VOICE_R;
   1009 		goto lr;
   1010 	case EAP_FM_VOL:
   1011 		la = AK_FM_L;
   1012 		ra = AK_FM_R;
   1013 		goto lr;
   1014 	case EAP_CD_VOL:
   1015 		la = AK_CD_L;
   1016 		ra = AK_CD_R;
   1017 		goto lr;
   1018 	case EAP_LINE_VOL:
   1019 		la = AK_LINE_L;
   1020 		ra = AK_LINE_R;
   1021 		goto lr;
   1022 	case EAP_AUX_VOL:
   1023 		la = AK_AUX_L;
   1024 		ra = AK_AUX_R;
   1025 	lr:
   1026 		l = GAIN5_TO_VOL(sc->sc_port[la]);
   1027 		r = GAIN5_TO_VOL(sc->sc_port[ra]);
   1028 		break;
   1029 	default:
   1030 		return (EINVAL);
   1031 	}
   1032 	if (cp->un.value.num_channels == 1)
   1033 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
   1034 	else if (cp->un.value.num_channels == 2) {
   1035 		cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]  = l;
   1036 		cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
   1037 	}
   1038 	return (0);
   1039 }
   1040 
   1041 int
   1042 eap_query_devinfo(addr, dip)
   1043 	void *addr;
   1044 	mixer_devinfo_t *dip;
   1045 {
   1046 	switch (dip->index) {
   1047 	case EAP_MASTER_VOL:
   1048 		dip->type = AUDIO_MIXER_VALUE;
   1049 		dip->mixer_class = EAP_OUTPUT_CLASS;
   1050 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   1051 		strcpy(dip->label.name, AudioNmaster);
   1052 		dip->un.v.num_channels = 2;
   1053 		strcpy(dip->un.v.units.name, AudioNvolume);
   1054 		return (0);
   1055 	case EAP_VOICE_VOL:
   1056 		dip->type = AUDIO_MIXER_VALUE;
   1057 		dip->mixer_class = EAP_INPUT_CLASS;
   1058 		dip->prev = AUDIO_MIXER_LAST;
   1059 		dip->next = AUDIO_MIXER_LAST;
   1060 		strcpy(dip->label.name, AudioNdac);
   1061 		dip->un.v.num_channels = 2;
   1062 		strcpy(dip->un.v.units.name, AudioNvolume);
   1063 		return (0);
   1064 	case EAP_FM_VOL:
   1065 		dip->type = AUDIO_MIXER_VALUE;
   1066 		dip->mixer_class = EAP_INPUT_CLASS;
   1067 		dip->prev = AUDIO_MIXER_LAST;
   1068 		dip->next = AUDIO_MIXER_LAST;
   1069 		strcpy(dip->label.name, AudioNfmsynth);
   1070 		dip->un.v.num_channels = 2;
   1071 		strcpy(dip->un.v.units.name, AudioNvolume);
   1072 		return (0);
   1073 	case EAP_CD_VOL:
   1074 		dip->type = AUDIO_MIXER_VALUE;
   1075 		dip->mixer_class = EAP_INPUT_CLASS;
   1076 		dip->prev = AUDIO_MIXER_LAST;
   1077 		dip->next = AUDIO_MIXER_LAST;
   1078 		strcpy(dip->label.name, AudioNcd);
   1079 		dip->un.v.num_channels = 2;
   1080 		strcpy(dip->un.v.units.name, AudioNvolume);
   1081 		return (0);
   1082 	case EAP_LINE_VOL:
   1083 		dip->type = AUDIO_MIXER_VALUE;
   1084 		dip->mixer_class = EAP_INPUT_CLASS;
   1085 		dip->prev = AUDIO_MIXER_LAST;
   1086 		dip->next = AUDIO_MIXER_LAST;
   1087 		strcpy(dip->label.name, AudioNline);
   1088 		dip->un.v.num_channels = 2;
   1089 		strcpy(dip->un.v.units.name, AudioNvolume);
   1090 		return (0);
   1091 	case EAP_AUX_VOL:
   1092 		dip->type = AUDIO_MIXER_VALUE;
   1093 		dip->mixer_class = EAP_INPUT_CLASS;
   1094 		dip->prev = AUDIO_MIXER_LAST;
   1095 		dip->next = AUDIO_MIXER_LAST;
   1096 		strcpy(dip->label.name, AudioNaux);
   1097 		dip->un.v.num_channels = 2;
   1098 		strcpy(dip->un.v.units.name, AudioNvolume);
   1099 		return (0);
   1100 	case EAP_MIC_VOL:
   1101 		dip->type = AUDIO_MIXER_VALUE;
   1102 		dip->mixer_class = EAP_INPUT_CLASS;
   1103 		dip->prev = AUDIO_MIXER_LAST;
   1104 		dip->next = AUDIO_MIXER_LAST;
   1105 		strcpy(dip->label.name, AudioNmicrophone);
   1106 		dip->un.v.num_channels = 1;
   1107 		strcpy(dip->un.v.units.name, AudioNvolume);
   1108 		return (0);
   1109 	case EAP_RECORD_SOURCE:
   1110 		dip->mixer_class = EAP_RECORD_CLASS;
   1111 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   1112 		strcpy(dip->label.name, AudioNsource);
   1113 		dip->type = AUDIO_MIXER_SET;
   1114 		dip->un.s.num_mem = 5;
   1115 		strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
   1116 		dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
   1117 		strcpy(dip->un.s.member[1].label.name, AudioNcd);
   1118 		dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
   1119 		strcpy(dip->un.s.member[2].label.name, AudioNline);
   1120 		dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
   1121 		strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
   1122 		dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
   1123 		strcpy(dip->un.s.member[4].label.name, AudioNaux);
   1124 		dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
   1125 		return (0);
   1126 	case EAP_OUTPUT_CLASS:
   1127 		dip->type = AUDIO_MIXER_CLASS;
   1128 		dip->mixer_class = EAP_OUTPUT_CLASS;
   1129 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1130 		strcpy(dip->label.name, AudioCoutputs);
   1131 		return (0);
   1132 	case EAP_RECORD_CLASS:
   1133 		dip->type = AUDIO_MIXER_CLASS;
   1134 		dip->mixer_class = EAP_RECORD_CLASS;
   1135 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1136 		strcpy(dip->label.name, AudioCrecord);
   1137 		return (0);
   1138 	case EAP_INPUT_CLASS:
   1139 		dip->type = AUDIO_MIXER_CLASS;
   1140 		dip->mixer_class = EAP_INPUT_CLASS;
   1141 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1142 		strcpy(dip->label.name, AudioCinputs);
   1143 		return (0);
   1144 	}
   1145 	return (ENXIO);
   1146 }
   1147 
   1148 void *
   1149 eap_malloc(addr, size, pool, flags)
   1150 	void *addr;
   1151 	u_long size;
   1152 	int pool;
   1153 	int flags;
   1154 {
   1155 	struct eap_softc *sc = addr;
   1156         struct eap_dma *p;
   1157         int error;
   1158 
   1159         p = malloc(sizeof(*p), pool, flags);
   1160         if (!p)
   1161                 return (0);
   1162         error = eap_allocmem(sc, size, 16, p);
   1163         if (error) {
   1164                 free(p, pool);
   1165         	return (0);
   1166         }
   1167         p->next = sc->sc_dmas;
   1168         sc->sc_dmas = p;
   1169 	return (KERNADDR(p));
   1170 }
   1171 
   1172 void
   1173 eap_free(addr, ptr, pool)
   1174 	void *addr;
   1175 	void *ptr;
   1176 	int pool;
   1177 {
   1178 	struct eap_softc *sc = addr;
   1179         struct eap_dma **p;
   1180 
   1181         for (p = &sc->sc_dmas; *p; p = &(*p)->next) {
   1182                 if (KERNADDR(*p) == ptr) {
   1183                         eap_freemem(sc, *p);
   1184                         *p = (*p)->next;
   1185                         free(*p, pool);
   1186                         return;
   1187                 }
   1188         }
   1189 }
   1190 
   1191 u_long
   1192 eap_round(addr, size)
   1193 	void *addr;
   1194 	u_long size;
   1195 {
   1196 	return (size);
   1197 }
   1198 
   1199 int
   1200 eap_mappage(addr, mem, off, prot)
   1201 	void *addr;
   1202         void *mem;
   1203         int off;
   1204 	int prot;
   1205 {
   1206 	struct eap_softc *sc = addr;
   1207         struct eap_dma *p;
   1208 
   1209         for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
   1210 		;
   1211 	if (!p)
   1212 		return (-1);
   1213 	return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
   1214 				off, prot, BUS_DMA_WAITOK));
   1215 }
   1216 
   1217 int
   1218 eap_get_props(addr)
   1219 	void *addr;
   1220 {
   1221 	return (AUDIO_PROP_MMAP | AUDIO_PROP_FULLDUPLEX);
   1222 }
   1223