Home | History | Annotate | Line # | Download | only in pci
eap.c revision 1.7
      1 /*	$NetBSD: eap.c,v 1.7 1998/06/08 06:55:54 thorpej 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 int	eap_match __P((struct device *, struct cfdata *, void *));
    248 void	eap_attach __P((struct device *, struct device *, void *));
    249 int	eap_intr __P((void *));
    250 
    251 struct eap_dma {
    252 	bus_dmamap_t map;
    253         caddr_t addr;
    254         bus_dma_segment_t segs[1];
    255         int nsegs;
    256         size_t size;
    257         struct eap_dma *next;
    258 };
    259 #define DMAADDR(map) ((map)->segs[0].ds_addr)
    260 #define KERNADDR(map) ((void *)((map)->addr))
    261 
    262 struct eap_softc {
    263 	struct device sc_dev;		/* base device */
    264 	void *sc_ih;			/* interrupt vectoring */
    265 	bus_space_tag_t iot;
    266 	bus_space_handle_t ioh;
    267 	bus_dma_tag_t sc_dmatag;	/* DMA tag */
    268 
    269         struct eap_dma *sc_dmas;
    270 
    271 	void	(*sc_pintr)(void *);	/* dma completion intr handler */
    272 	void	*sc_parg;		/* arg for sc_intr() */
    273 	char	sc_prun;
    274 
    275 	void	(*sc_rintr)(void *);	/* dma completion intr handler */
    276 	void	*sc_rarg;		/* arg for sc_intr() */
    277 	char	sc_rrun;
    278 
    279 	int	sc_sampsize;		/* bytes / sample */
    280 
    281 	u_char	sc_port[AK_NPORTS];	/* mirror of the hardware setting */
    282 	u_int	sc_record_source;	/* recording source mask */
    283 };
    284 
    285 int	eap_allocmem __P((struct eap_softc *, size_t, size_t, struct eap_dma *));
    286 int	eap_freemem __P((struct eap_softc *, struct eap_dma *));
    287 
    288 #define EWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
    289 #define EWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
    290 #define EREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
    291 #define EREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
    292 
    293 struct cfattach eap_ca = {
    294 	sizeof(struct eap_softc), eap_match, eap_attach
    295 };
    296 
    297 int	eap_open __P((void *, int));
    298 void	eap_close __P((void *));
    299 int	eap_query_encoding __P((void *, struct audio_encoding *));
    300 int	eap_set_params __P((void *, int, int, struct audio_params *, struct audio_params *));
    301 int	eap_round_blocksize __P((void *, int));
    302 int	eap_dma_init_output __P((void *, void *, int));
    303 int	eap_dma_init_input __P((void *, void *, int));
    304 int	eap_dma_output __P((void *, void *, int, void (*)(void *), void*));
    305 int	eap_dma_input __P((void *, void *, int, void (*)(void *), void*));
    306 int	eap_halt_in_dma __P((void *));
    307 int	eap_halt_out_dma __P((void *));
    308 int	eap_getdev __P((void *, struct audio_device *));
    309 int	eap_mixer_set_port __P((void *, mixer_ctrl_t *));
    310 int	eap_mixer_get_port __P((void *, mixer_ctrl_t *));
    311 int	eap_query_devinfo __P((void *, mixer_devinfo_t *));
    312 void   *eap_malloc __P((void *, u_long, int, int));
    313 void	eap_free __P((void *, void *, int));
    314 u_long	eap_round __P((void *, u_long));
    315 int	eap_mappage __P((void *, void *, int, int));
    316 int	eap_get_props __P((void *));
    317 void	eap_write_codec __P((struct eap_softc *sc, int a, int d));
    318 void	eap_set_mixer __P((struct eap_softc *sc, int a, int d));
    319 
    320 struct audio_hw_if eap_hw_if = {
    321 	eap_open,
    322 	eap_close,
    323 	NULL,
    324 	eap_query_encoding,
    325 	eap_set_params,
    326 	eap_round_blocksize,
    327 	NULL,
    328 	eap_dma_init_output,
    329 	eap_dma_init_input,
    330 	eap_dma_output,
    331 	eap_dma_input,
    332 	eap_halt_out_dma,
    333 	eap_halt_in_dma,
    334 	NULL,
    335 	eap_getdev,
    336 	NULL,
    337 	eap_mixer_set_port,
    338 	eap_mixer_get_port,
    339 	eap_query_devinfo,
    340 	eap_malloc,
    341 	eap_free,
    342 	eap_round,
    343 	eap_mappage,
    344 	eap_get_props,
    345 };
    346 
    347 struct audio_device eap_device = {
    348 	"Ensoniq AudioPCI",
    349 	"",
    350 	"eap"
    351 };
    352 
    353 int
    354 eap_match(parent, match, aux)
    355 	struct device *parent;
    356 	struct cfdata *match;
    357 	void *aux;
    358 {
    359 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    360 
    361 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_ENSONIQ)
    362 		return (0);
    363 	if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_ENSONIQ_AUDIOPCI)
    364 		return (0);
    365 
    366 	return (1);
    367 }
    368 
    369 void
    370 eap_write_codec(sc, a, d)
    371 	struct eap_softc *sc;
    372 	int a, d;
    373 {
    374 	int icss;
    375 
    376 	do {
    377 	        icss = EREAD4(sc, EAP_ICSS);
    378 		DPRINTFN(5,("eap: codec %d prog: icss=0x%08x\n", a, icss));
    379 	} while(icss & EAP_CWRIP);
    380 	EWRITE4(sc, EAP_CODEC, EAP_SET_CODEC(a, d));
    381 }
    382 
    383 void
    384 eap_attach(parent, self, aux)
    385 	struct device *parent;
    386 	struct device *self;
    387 	void *aux;
    388 {
    389 	struct eap_softc *sc = (struct eap_softc *)self;
    390 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    391 	pci_chipset_tag_t pc = pa->pa_pc;
    392 	char const *intrstr;
    393 	pci_intr_handle_t ih;
    394 	pcireg_t csr;
    395 	char devinfo[256];
    396 	mixer_ctrl_t ctl;
    397 
    398 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    399 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    400 
    401 	/* Map I/O register */
    402 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    403 	      &sc->iot, &sc->ioh, NULL, NULL)) {
    404 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    405 		return;
    406 	}
    407 
    408 	sc->sc_dmatag = pa->pa_dmat;
    409 
    410 	/* Enable the device. */
    411 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    412 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    413 		       csr | PCI_COMMAND_MASTER_ENABLE);
    414 
    415 	/* Map and establish the interrupt. */
    416 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    417 	    pa->pa_intrline, &ih)) {
    418 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    419 		return;
    420 	}
    421 	intrstr = pci_intr_string(pc, ih);
    422 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, eap_intr, sc);
    423 	if (sc->sc_ih == NULL) {
    424 		printf("%s: couldn't establish interrupt",
    425 		    sc->sc_dev.dv_xname);
    426 		if (intrstr != NULL)
    427 			printf(" at %s", intrstr);
    428 		printf("\n");
    429 		return;
    430 	}
    431 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    432 
    433 	/* Enable interrupts and looping mode. */
    434         EWRITE4(sc, EAP_SIC, EAP_P2_INTR_EN | EAP_R1_INTR_EN);
    435         EWRITE4(sc, EAP_ICSC, EAP_CDC_EN); /* enable the parts we need */
    436 
    437 	eap_write_codec(sc, AK_RESET, AK_PD); /* reset codec */
    438 	eap_write_codec(sc, AK_RESET, AK_PD | AK_NRST);	/* normal operation */
    439 	eap_write_codec(sc, AK_CS, 0x0); /* select codec clocks */
    440 	/* Enable all relevant mixer switches. */
    441 	eap_write_codec(sc, AK_OUT_MIXER1,
    442 			AK_M_FM_L | AK_M_FM_R |
    443 			AK_M_LINE_L | AK_M_LINE_R |
    444 			AK_M_CD_L | AK_M_CD_R);
    445 	eap_write_codec(sc, AK_OUT_MIXER2,
    446 			AK_M_AUX_L | AK_M_AUX_R |
    447 			AK_M_VOICE_L | AK_M_VOICE_R |
    448 			AK_M_MONO2 | AK_M_MONO1);
    449 	ctl.type = AUDIO_MIXER_VALUE;
    450 	ctl.un.value.num_channels = 1;
    451 	for (ctl.dev = EAP_MASTER_VOL; ctl.dev < EAP_MIC_VOL; ctl.dev++) {
    452 		ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = VOL_0DB;
    453 		eap_mixer_set_port(sc, &ctl);
    454 	}
    455 	ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = 0;
    456 	eap_mixer_set_port(sc, &ctl); /* set the mic to 0 */
    457 	ctl.dev = EAP_RECORD_SOURCE;
    458 	ctl.type = AUDIO_MIXER_SET;
    459 	ctl.un.mask = 1 << EAP_MIC_VOL;
    460 	eap_mixer_set_port(sc, &ctl);
    461 
    462         audio_attach_mi(&eap_hw_if, 0, sc, &sc->sc_dev);
    463 }
    464 
    465 int
    466 eap_intr(p)
    467 	void *p;
    468 {
    469 	struct eap_softc *sc = p;
    470 	u_int32_t intr, sic;
    471 
    472         intr = EREAD4(sc, EAP_ICSS);
    473         if (!(intr & EAP_INTR))
    474         	return (0);
    475 	sic = EREAD4(sc, EAP_SIC);
    476 	DPRINTFN(5, ("eap_intr: ICSS=0x%08x, SIC=0x%08x\n", intr, sic));
    477         if (intr & EAP_I_ADC) {
    478         	/*
    479                  * XXX This is a hack!
    480                  * The EAP chip sometimes generates the recording interrupt
    481                  * while it is still transferring the data.  To make sure
    482                  * it has all arrived we busy wait until the count is right.
    483                  * The transfer we are waiting for is 8 longwords.
    484                  */
    485         	int s, nw, n;
    486                 EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
    487                 s = EREAD4(sc, EAP_ADC_CSR);
    488                 nw = ((s & 0xffff) + 1) / 4; /* # of words in DMA */
    489                 n = 0;
    490                 while (((EREAD4(sc, EAP_ADC_SIZE) >> 16) + 8) % nw == 0) {
    491                 	delay(10);
    492                 	if (++n > 100) {
    493                 		printf("eapintr: dma fix timeout");
    494                                 break;
    495                         }
    496                 }
    497                 /* Continue with normal interrupt handling. */
    498 		EWRITE4(sc, EAP_SIC, sic & ~EAP_R1_INTR_EN);
    499 		EWRITE4(sc, EAP_SIC, sic);
    500                 if (sc->sc_rintr)
    501 	        	sc->sc_rintr(sc->sc_rarg);
    502         }
    503         if (intr & EAP_I_DAC2) {
    504 		EWRITE4(sc, EAP_SIC, sic & ~EAP_P2_INTR_EN);
    505 		EWRITE4(sc, EAP_SIC, sic);
    506                 if (sc->sc_pintr)
    507 	        	sc->sc_pintr(sc->sc_parg);
    508         }
    509 	return (1);
    510 }
    511 
    512 int
    513 eap_allocmem(sc, size, align, p)
    514 	struct eap_softc *sc;
    515 	size_t size;
    516 	size_t align;
    517         struct eap_dma *p;
    518 {
    519 	int error;
    520 
    521 	p->size = size;
    522 	error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
    523 				 p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
    524 				 &p->nsegs, BUS_DMA_NOWAIT);
    525 	if (error)
    526 		return (error);
    527 
    528 	error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
    529 			       &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    530 	if (error)
    531 		goto free;
    532 
    533 	error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
    534 				  0, BUS_DMA_NOWAIT, &p->map);
    535 	if (error)
    536 		goto unmap;
    537 
    538 	error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
    539 				BUS_DMA_NOWAIT);
    540 	if (error)
    541 		goto destroy;
    542 	return (0);
    543 
    544 destroy:
    545 	bus_dmamap_destroy(sc->sc_dmatag, p->map);
    546 unmap:
    547 	bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
    548 free:
    549 	bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
    550 	return (error);
    551 }
    552 
    553 int
    554 eap_freemem(sc, p)
    555 	struct eap_softc *sc;
    556         struct eap_dma *p;
    557 {
    558 	bus_dmamap_unload(sc->sc_dmatag, p->map);
    559 	bus_dmamap_destroy(sc->sc_dmatag, p->map);
    560 	bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
    561 	bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
    562 	return (0);
    563 }
    564 
    565 int
    566 eap_open(addr, flags)
    567 	void *addr;
    568 	int flags;
    569 {
    570 	struct eap_softc *sc = addr;
    571 
    572         DPRINTF(("eap_open: sc=%p\n", sc));
    573 
    574         sc->sc_pintr = 0;
    575         sc->sc_rintr = 0;
    576 
    577         return (0);
    578 }
    579 
    580 /*
    581  * Close function is called at splaudio().
    582  */
    583 void
    584 eap_close(addr)
    585 	void *addr;
    586 {
    587 	struct eap_softc *sc = addr;
    588 
    589         eap_halt_in_dma(sc);
    590         eap_halt_out_dma(sc);
    591 
    592         sc->sc_pintr = 0;
    593         sc->sc_rintr = 0;
    594 }
    595 
    596 int
    597 eap_query_encoding(addr, fp)
    598 	void *addr;
    599 	struct audio_encoding *fp;
    600 {
    601 	switch (fp->index) {
    602 	case 0:
    603 		strcpy(fp->name, AudioEulinear);
    604 		fp->encoding = AUDIO_ENCODING_ULINEAR;
    605 		fp->precision = 8;
    606 		fp->flags = 0;
    607 		return (0);
    608 	case 1:
    609 		strcpy(fp->name, AudioEmulaw);
    610 		fp->encoding = AUDIO_ENCODING_ULAW;
    611 		fp->precision = 8;
    612 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    613 		return (0);
    614 	case 2:
    615 		strcpy(fp->name, AudioEalaw);
    616 		fp->encoding = AUDIO_ENCODING_ALAW;
    617 		fp->precision = 8;
    618 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    619 		return (0);
    620 	case 3:
    621 		strcpy(fp->name, AudioEslinear);
    622 		fp->encoding = AUDIO_ENCODING_SLINEAR;
    623 		fp->precision = 8;
    624 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    625 		return (0);
    626         case 4:
    627 		strcpy(fp->name, AudioEslinear_le);
    628 		fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
    629 		fp->precision = 16;
    630 		fp->flags = 0;
    631 		return (0);
    632 	case 5:
    633 		strcpy(fp->name, AudioEulinear_le);
    634 		fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
    635 		fp->precision = 16;
    636 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    637 		return (0);
    638 	case 6:
    639 		strcpy(fp->name, AudioEslinear_be);
    640 		fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
    641 		fp->precision = 16;
    642 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    643 		return (0);
    644 	case 7:
    645 		strcpy(fp->name, AudioEulinear_be);
    646 		fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
    647 		fp->precision = 16;
    648 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    649 		return (0);
    650 	default:
    651 		return (EINVAL);
    652 	}
    653 }
    654 
    655 int
    656 eap_set_params(addr, setmode, usemode, p, r)
    657 	void *addr;
    658 	int setmode, usemode;
    659 	struct audio_params *p, *r;
    660 {
    661 	struct eap_softc *sc = addr;
    662 	void (*pswcode) __P((void *, u_char *buf, int cnt));
    663 	void (*rswcode) __P((void *, u_char *buf, int cnt));
    664         u_int32_t mode, div;
    665 
    666 
    667         pswcode = rswcode = 0;
    668         switch (p->encoding) {
    669         case AUDIO_ENCODING_SLINEAR_BE:
    670         	if (p->precision == 16)
    671                 	rswcode = pswcode = swap_bytes;
    672 		else
    673 			pswcode = rswcode = change_sign8;
    674 		break;
    675         case AUDIO_ENCODING_SLINEAR_LE:
    676         	if (p->precision != 16)
    677 			pswcode = rswcode = change_sign8;
    678         	break;
    679         case AUDIO_ENCODING_ULINEAR_BE:
    680         	if (p->precision == 16) {
    681 			pswcode = swap_bytes_change_sign16;
    682 			rswcode = change_sign16_swap_bytes;
    683 		}
    684 		break;
    685         case AUDIO_ENCODING_ULINEAR_LE:
    686         	if (p->precision == 16)
    687 			pswcode = rswcode = change_sign16;
    688         	break;
    689         case AUDIO_ENCODING_ULAW:
    690         	pswcode = mulaw_to_ulinear8;
    691                 rswcode = ulinear8_to_mulaw;
    692                 break;
    693         case AUDIO_ENCODING_ALAW:
    694                 pswcode = alaw_to_ulinear8;
    695                 rswcode = ulinear8_to_alaw;
    696                 break;
    697         default:
    698         	return (EINVAL);
    699         }
    700 	if (p->precision == 16)
    701 		mode = EAP_P2_S_EB | EAP_R1_S_EB;
    702 	else
    703 		mode = 0;
    704         if (p->channels == 2)
    705         	mode |= EAP_P2_S_MB | EAP_R1_S_MB;
    706 	else if (p->channels != 1)
    707 		return (EINVAL);
    708         if (p->sample_rate < 4000 || p->sample_rate > 50000)
    709         	return (EINVAL);
    710 
    711 	sc->sc_sampsize = p->precision / 8 * p->channels; /* bytes / sample */
    712         p->sw_code = pswcode;
    713         r->sw_code = rswcode;
    714 
    715         /* Set the encoding */
    716         mode |= EREAD4(sc, EAP_SIC) & ~(EAP_R1P2_BITS | EAP_INC_BITS);
    717 	mode |= EAP_SET_P2_ST_INC(0) | EAP_SET_P2_END_INC(p->precision / 8);
    718         EWRITE4(sc, EAP_SIC, mode);
    719 	DPRINTFN(2, ("eap_set_params: set SIC = 0x%08x\n", mode));
    720 
    721         /* Set the speed */
    722 	DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n",
    723 		     EREAD4(sc, EAP_ICSC)));
    724 	div = EREAD4(sc, EAP_ICSC) & ~EAP_PCLKBITS;
    725         div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ / p->sample_rate - 2);
    726 	div |= EAP_CCB_INTRM;
    727         EWRITE4(sc, EAP_ICSC, div);
    728 	DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div));
    729 
    730         return (0);
    731 }
    732 
    733 int
    734 eap_round_blocksize(addr, blk)
    735 	void *addr;
    736 	int blk;
    737 {
    738 	return (blk & -32);	/* keep good alignment */
    739 }
    740 
    741 int
    742 eap_dma_init_input(addr, buf, cc)
    743 	void *addr;
    744 	void *buf;
    745 	int cc;
    746 {
    747 	struct eap_softc *sc = addr;
    748 	struct eap_dma *p;
    749 
    750 	DPRINTF(("eap_dma_init_input: dma start loop input addr=%p cc=%d\n",
    751 		 buf, cc));
    752         for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
    753 		;
    754 	if (!p) {
    755 		printf("eap_dma_init_input: bad addr %p\n", buf);
    756 		return (EINVAL);
    757 	}
    758 	EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
    759 	EWRITE4(sc, EAP_ADC_ADDR, DMAADDR(p));
    760 	EWRITE4(sc, EAP_ADC_SIZE, EAP_SET_SIZE(0, cc / 4 - 1));
    761 	DPRINTF(("eap_dma_init_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
    762 		 (int)DMAADDR(p), EAP_SET_SIZE(0, cc / 4 - 1)));
    763 	return (0);
    764 }
    765 
    766 int
    767 eap_dma_init_output(addr, buf, cc)
    768 	void *addr;
    769 	void *buf;
    770 	int cc;
    771 {
    772 	struct eap_softc *sc = addr;
    773 	struct eap_dma *p;
    774 
    775 	DPRINTF(("eap: dma start loop output buf=%p cc=%d\n", buf, cc));
    776         for (p = sc->sc_dmas; p && KERNADDR(p) != buf; p = p->next)
    777 		;
    778 	if (!p) {
    779 		printf("eap_dma_init_output: bad addr %p\n", buf);
    780 		return (EINVAL);
    781 	}
    782 	EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
    783 	EWRITE4(sc, EAP_DAC2_ADDR, DMAADDR(p));
    784 	EWRITE4(sc, EAP_DAC2_SIZE, EAP_SET_SIZE(0, cc / 4 - 1));
    785 	DPRINTF(("eap_dma_init_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
    786 		 (int)DMAADDR(p), EAP_SET_SIZE(0, cc / 4 - 1)));
    787 	return (0);
    788 }
    789 
    790 int
    791 eap_dma_output(addr, p, cc, intr, arg)
    792 	void *addr;
    793 	void *p;
    794 	int cc;
    795 	void (*intr) __P((void *));
    796 	void *arg;
    797 {
    798 	struct eap_softc *sc = addr;
    799 	u_int32_t mode;
    800 
    801 	DPRINTFN(sc->sc_prun ? 5 : 1,
    802                  ("eap_dma_output: sc=%p buf=%p cc=%d intr=%p(%p)\n",
    803                   addr, p, cc, intr, arg));
    804 	sc->sc_pintr = intr;
    805 	sc->sc_parg = arg;
    806 	if (!sc->sc_prun) {
    807 #if defined(DIAGNOSTIC) || defined(AUDIO_DEBUG)
    808 	        if (sc->sc_sampsize == 0) {
    809         		printf("eap_dma_output: sampsize == 0\n");
    810                         return EINVAL;
    811                 }
    812 #endif
    813 		EWRITE2(sc, EAP_DAC2_CSR, cc / sc->sc_sampsize - 1);
    814 		DPRINTFN(1, ("eap_dma_output: set DAC2_CSR = %d\n",
    815 			     cc / sc->sc_sampsize - 1));
    816 		DPRINTFN(1, ("eap_dma_output: old ICSC = 0x%08x\n",
    817 			     EREAD4(sc, EAP_ICSC)));
    818 		mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
    819 		EWRITE4(sc, EAP_ICSC, mode);
    820 		mode |= EAP_DAC2_EN;
    821 		EWRITE4(sc, EAP_ICSC, mode);
    822 		DPRINTFN(1, ("eap_dma_output: set ICSC = 0x%08x\n", mode));
    823 		sc->sc_prun = 1;
    824 	}
    825         return (0);
    826 }
    827 
    828 int
    829 eap_dma_input(addr, p, cc, intr, arg)
    830 	void *addr;
    831 	void *p;
    832 	int cc;
    833 	void (*intr) __P((void *));
    834 	void *arg;
    835 {
    836 	struct eap_softc *sc = addr;
    837 	u_int32_t mode;
    838 
    839 	DPRINTFN(1, ("eap_dma_input: sc=%p buf=%p cc=%d intr=%p(%p)\n",
    840 		     addr, p, cc, intr, arg));
    841 	sc->sc_rintr = intr;
    842 	sc->sc_rarg = arg;
    843 	if (!sc->sc_rrun) {
    844 #if defined(DIAGNOSTIC) || defined(AUDIO_DEBUG)
    845 	        if (sc->sc_sampsize == 0) {
    846         		printf("eap_dma_input: sampsize == 0\n");
    847                         return EINVAL;
    848                 }
    849 #endif
    850 		EWRITE2(sc, EAP_ADC_CSR, cc / sc->sc_sampsize - 1);
    851 		mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
    852 		EWRITE4(sc, EAP_ICSC, mode);
    853 		mode |= EAP_ADC_EN;
    854 		EWRITE4(sc, EAP_ICSC, mode);
    855 		DPRINTFN(1, ("eap_dma_input: set ICSC = 0x%08x\n", mode));
    856 		sc->sc_rrun = 1;
    857 	}
    858         return (0);
    859 }
    860 
    861 int
    862 eap_halt_out_dma(addr)
    863 	void *addr;
    864 {
    865 	struct eap_softc *sc = addr;
    866 	u_int32_t mode;
    867 
    868         DPRINTF(("eap: eap_halt_out_dma\n"));
    869 	mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
    870 	EWRITE4(sc, EAP_ICSC, mode);
    871 	sc->sc_prun = 0;
    872         return (0);
    873 }
    874 
    875 int
    876 eap_halt_in_dma(addr)
    877 	void *addr;
    878 {
    879 	struct eap_softc *sc = addr;
    880 	u_int32_t mode;
    881 
    882         DPRINTF(("eap: eap_halt_in_dma\n"));
    883 	mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
    884 	EWRITE4(sc, EAP_ICSC, mode);
    885 	sc->sc_rrun = 0;
    886         return (0);
    887 }
    888 
    889 int
    890 eap_getdev(addr, retp)
    891 	void *addr;
    892         struct audio_device *retp;
    893 {
    894 	*retp = eap_device;
    895         return (0);
    896 }
    897 
    898 void
    899 eap_set_mixer(sc, a, d)
    900 	struct eap_softc *sc;
    901         int a, d;
    902 {
    903 	eap_write_codec(sc, a, d);
    904         DPRINTFN(1, ("eap_mixer_set_port port 0x%02x = 0x%02x\n", a, d));
    905 }
    906 
    907 
    908 int
    909 eap_mixer_set_port(addr, cp)
    910 	void *addr;
    911 	mixer_ctrl_t *cp;
    912 {
    913 	struct eap_softc *sc = addr;
    914 	int lval, rval, l, r, la, ra;
    915 	int l1, r1, l2, r2, m;
    916 
    917 	if (cp->dev == EAP_RECORD_SOURCE) {
    918 		if (cp->type != AUDIO_MIXER_SET)
    919 			return (EINVAL);
    920 		m = sc->sc_record_source = cp->un.mask;
    921 		l1 = l2 = r1 = r2 = 0;
    922 		if (m & (1 << EAP_VOICE_VOL))
    923 			l2 |= AK_M_VOICE_L, r2 |= AK_M_VOICE_R;
    924 		if (m & (1 << EAP_FM_VOL))
    925 			l1 |= AK_M_FM_L, r1 |= AK_M_FM_R;
    926 		if (m & (1 << EAP_CD_VOL))
    927 			l1 |= AK_M_CD_L, r1 |= AK_M_CD_R;
    928 		if (m & (1 << EAP_LINE_VOL))
    929 			l1 |= AK_M_LINE_L, r1 |= AK_M_LINE_R;
    930 		if (m & (1 << EAP_AUX_VOL))
    931 			l2 |= AK_M_AUX_L, r2 |= AK_M_AUX_R;
    932 		if (m & (1 << EAP_MIC_VOL))
    933 			l2 |= AK_M_TMIC, r2 |= AK_M_TMIC;
    934 		eap_set_mixer(sc, AK_IN_MIXER1_L, l1);
    935 		eap_set_mixer(sc, AK_IN_MIXER1_R, r1);
    936 		eap_set_mixer(sc, AK_IN_MIXER2_L, l2);
    937 		eap_set_mixer(sc, AK_IN_MIXER2_R, r2);
    938 		return (0);
    939 	}
    940 	if (cp->type != AUDIO_MIXER_VALUE)
    941 		return (EINVAL);
    942 	if (cp->un.value.num_channels == 1)
    943 		lval = rval = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    944 	else if (cp->un.value.num_channels == 2) {
    945 		lval = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
    946 		rval = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
    947 	} else
    948 		return (EINVAL);
    949 	ra = -1;
    950 	switch (cp->dev) {
    951 	case EAP_MASTER_VOL:
    952 		l = VOL_TO_ATT5(lval);
    953 		r = VOL_TO_ATT5(rval);
    954 		la = AK_MASTER_L;
    955 		ra = AK_MASTER_R;
    956 		break;
    957 	case EAP_MIC_VOL:
    958 		if (cp->un.value.num_channels != 1)
    959 			return (EINVAL);
    960 		la = AK_MIC;
    961 		goto lr;
    962 	case EAP_VOICE_VOL:
    963 		la = AK_VOICE_L;
    964 		ra = AK_VOICE_R;
    965 		goto lr;
    966 	case EAP_FM_VOL:
    967 		la = AK_FM_L;
    968 		ra = AK_FM_R;
    969 		goto lr;
    970 	case EAP_CD_VOL:
    971 		la = AK_CD_L;
    972 		ra = AK_CD_R;
    973 		goto lr;
    974 	case EAP_LINE_VOL:
    975 		la = AK_LINE_L;
    976 		ra = AK_LINE_R;
    977 		goto lr;
    978 	case EAP_AUX_VOL:
    979 		la = AK_AUX_L;
    980 		ra = AK_AUX_R;
    981 	lr:
    982 		l = VOL_TO_GAIN5(lval);
    983 		r = VOL_TO_GAIN5(rval);
    984 		break;
    985 	default:
    986 		return (EINVAL);
    987 	}
    988 	eap_set_mixer(sc, la, l);
    989 	sc->sc_port[la] = l;
    990 	if (ra >= 0) {
    991 		eap_set_mixer(sc, ra, r);
    992 		sc->sc_port[ra] = r;
    993 	}
    994 	return (0);
    995 }
    996 
    997 int
    998 eap_mixer_get_port(addr, cp)
    999 	void *addr;
   1000 	mixer_ctrl_t *cp;
   1001 {
   1002 	struct eap_softc *sc = addr;
   1003 	int la, ra, l, r;
   1004 
   1005 	switch (cp->dev) {
   1006 	case EAP_RECORD_SOURCE:
   1007 		cp->un.mask = sc->sc_record_source;
   1008 		return (0);
   1009 	case EAP_MASTER_VOL:
   1010 		l = ATT5_TO_VOL(sc->sc_port[AK_MASTER_L]);
   1011 		r = ATT5_TO_VOL(sc->sc_port[AK_MASTER_R]);
   1012 		break;
   1013 	case EAP_MIC_VOL:
   1014 		if (cp->un.value.num_channels != 1)
   1015 			return (EINVAL);
   1016 		la = ra = AK_MIC;
   1017 		goto lr;
   1018 	case EAP_VOICE_VOL:
   1019 		la = AK_VOICE_L;
   1020 		ra = AK_VOICE_R;
   1021 		goto lr;
   1022 	case EAP_FM_VOL:
   1023 		la = AK_FM_L;
   1024 		ra = AK_FM_R;
   1025 		goto lr;
   1026 	case EAP_CD_VOL:
   1027 		la = AK_CD_L;
   1028 		ra = AK_CD_R;
   1029 		goto lr;
   1030 	case EAP_LINE_VOL:
   1031 		la = AK_LINE_L;
   1032 		ra = AK_LINE_R;
   1033 		goto lr;
   1034 	case EAP_AUX_VOL:
   1035 		la = AK_AUX_L;
   1036 		ra = AK_AUX_R;
   1037 	lr:
   1038 		l = GAIN5_TO_VOL(sc->sc_port[la]);
   1039 		r = GAIN5_TO_VOL(sc->sc_port[ra]);
   1040 		break;
   1041 	default:
   1042 		return (EINVAL);
   1043 	}
   1044 	if (cp->un.value.num_channels == 1)
   1045 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
   1046 	else if (cp->un.value.num_channels == 2) {
   1047 		cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]  = l;
   1048 		cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
   1049 	}
   1050 	return (0);
   1051 }
   1052 
   1053 int
   1054 eap_query_devinfo(addr, dip)
   1055 	void *addr;
   1056 	mixer_devinfo_t *dip;
   1057 {
   1058 	switch (dip->index) {
   1059 	case EAP_MASTER_VOL:
   1060 		dip->type = AUDIO_MIXER_VALUE;
   1061 		dip->mixer_class = EAP_OUTPUT_CLASS;
   1062 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   1063 		strcpy(dip->label.name, AudioNmaster);
   1064 		dip->un.v.num_channels = 2;
   1065 		strcpy(dip->un.v.units.name, AudioNvolume);
   1066 		return (0);
   1067 	case EAP_VOICE_VOL:
   1068 		dip->type = AUDIO_MIXER_VALUE;
   1069 		dip->mixer_class = EAP_INPUT_CLASS;
   1070 		dip->prev = AUDIO_MIXER_LAST;
   1071 		dip->next = AUDIO_MIXER_LAST;
   1072 		strcpy(dip->label.name, AudioNdac);
   1073 		dip->un.v.num_channels = 2;
   1074 		strcpy(dip->un.v.units.name, AudioNvolume);
   1075 		return (0);
   1076 	case EAP_FM_VOL:
   1077 		dip->type = AUDIO_MIXER_VALUE;
   1078 		dip->mixer_class = EAP_INPUT_CLASS;
   1079 		dip->prev = AUDIO_MIXER_LAST;
   1080 		dip->next = AUDIO_MIXER_LAST;
   1081 		strcpy(dip->label.name, AudioNfmsynth);
   1082 		dip->un.v.num_channels = 2;
   1083 		strcpy(dip->un.v.units.name, AudioNvolume);
   1084 		return (0);
   1085 	case EAP_CD_VOL:
   1086 		dip->type = AUDIO_MIXER_VALUE;
   1087 		dip->mixer_class = EAP_INPUT_CLASS;
   1088 		dip->prev = AUDIO_MIXER_LAST;
   1089 		dip->next = AUDIO_MIXER_LAST;
   1090 		strcpy(dip->label.name, AudioNcd);
   1091 		dip->un.v.num_channels = 2;
   1092 		strcpy(dip->un.v.units.name, AudioNvolume);
   1093 		return (0);
   1094 	case EAP_LINE_VOL:
   1095 		dip->type = AUDIO_MIXER_VALUE;
   1096 		dip->mixer_class = EAP_INPUT_CLASS;
   1097 		dip->prev = AUDIO_MIXER_LAST;
   1098 		dip->next = AUDIO_MIXER_LAST;
   1099 		strcpy(dip->label.name, AudioNline);
   1100 		dip->un.v.num_channels = 2;
   1101 		strcpy(dip->un.v.units.name, AudioNvolume);
   1102 		return (0);
   1103 	case EAP_AUX_VOL:
   1104 		dip->type = AUDIO_MIXER_VALUE;
   1105 		dip->mixer_class = EAP_INPUT_CLASS;
   1106 		dip->prev = AUDIO_MIXER_LAST;
   1107 		dip->next = AUDIO_MIXER_LAST;
   1108 		strcpy(dip->label.name, AudioNaux);
   1109 		dip->un.v.num_channels = 2;
   1110 		strcpy(dip->un.v.units.name, AudioNvolume);
   1111 		return (0);
   1112 	case EAP_MIC_VOL:
   1113 		dip->type = AUDIO_MIXER_VALUE;
   1114 		dip->mixer_class = EAP_INPUT_CLASS;
   1115 		dip->prev = AUDIO_MIXER_LAST;
   1116 		dip->next = AUDIO_MIXER_LAST;
   1117 		strcpy(dip->label.name, AudioNmicrophone);
   1118 		dip->un.v.num_channels = 1;
   1119 		strcpy(dip->un.v.units.name, AudioNvolume);
   1120 		return (0);
   1121 	case EAP_RECORD_SOURCE:
   1122 		dip->mixer_class = EAP_RECORD_CLASS;
   1123 		dip->prev = dip->next = AUDIO_MIXER_LAST;
   1124 		strcpy(dip->label.name, AudioNsource);
   1125 		dip->type = AUDIO_MIXER_SET;
   1126 		dip->un.s.num_mem = 5;
   1127 		strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
   1128 		dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
   1129 		strcpy(dip->un.s.member[1].label.name, AudioNcd);
   1130 		dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
   1131 		strcpy(dip->un.s.member[2].label.name, AudioNline);
   1132 		dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
   1133 		strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
   1134 		dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
   1135 		strcpy(dip->un.s.member[4].label.name, AudioNaux);
   1136 		dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
   1137 		return (0);
   1138 	case EAP_OUTPUT_CLASS:
   1139 		dip->type = AUDIO_MIXER_CLASS;
   1140 		dip->mixer_class = EAP_OUTPUT_CLASS;
   1141 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1142 		strcpy(dip->label.name, AudioCoutputs);
   1143 		return (0);
   1144 	case EAP_RECORD_CLASS:
   1145 		dip->type = AUDIO_MIXER_CLASS;
   1146 		dip->mixer_class = EAP_RECORD_CLASS;
   1147 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1148 		strcpy(dip->label.name, AudioCrecord);
   1149 		return (0);
   1150 	case EAP_INPUT_CLASS:
   1151 		dip->type = AUDIO_MIXER_CLASS;
   1152 		dip->mixer_class = EAP_INPUT_CLASS;
   1153 		dip->next = dip->prev = AUDIO_MIXER_LAST;
   1154 		strcpy(dip->label.name, AudioCinputs);
   1155 		return (0);
   1156 	}
   1157 	return (ENXIO);
   1158 }
   1159 
   1160 void *
   1161 eap_malloc(addr, size, pool, flags)
   1162 	void *addr;
   1163 	u_long size;
   1164 	int pool;
   1165 	int flags;
   1166 {
   1167 	struct eap_softc *sc = addr;
   1168         struct eap_dma *p;
   1169         int error;
   1170 
   1171         p = malloc(sizeof(*p), pool, flags);
   1172         if (!p)
   1173                 return (0);
   1174         error = eap_allocmem(sc, size, 16, p);
   1175         if (error) {
   1176                 free(p, pool);
   1177         	return (0);
   1178         }
   1179         p->next = sc->sc_dmas;
   1180         sc->sc_dmas = p;
   1181 	return (KERNADDR(p));
   1182 }
   1183 
   1184 void
   1185 eap_free(addr, ptr, pool)
   1186 	void *addr;
   1187 	void *ptr;
   1188 	int pool;
   1189 {
   1190 	struct eap_softc *sc = addr;
   1191         struct eap_dma **p;
   1192 
   1193         for (p = &sc->sc_dmas; *p; p = &(*p)->next) {
   1194                 if (KERNADDR(*p) == ptr) {
   1195                         eap_freemem(sc, *p);
   1196                         *p = (*p)->next;
   1197                         free(*p, pool);
   1198                         return;
   1199                 }
   1200         }
   1201 }
   1202 
   1203 u_long
   1204 eap_round(addr, size)
   1205 	void *addr;
   1206 	u_long size;
   1207 {
   1208 	return (size);
   1209 }
   1210 
   1211 int
   1212 eap_mappage(addr, mem, off, prot)
   1213 	void *addr;
   1214         void *mem;
   1215         int off;
   1216 	int prot;
   1217 {
   1218 	struct eap_softc *sc = addr;
   1219         struct eap_dma *p;
   1220 
   1221         for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
   1222 		;
   1223 	if (!p)
   1224 		return (-1);
   1225 	return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
   1226 				off, prot, BUS_DMA_WAITOK));
   1227 }
   1228 
   1229 int
   1230 eap_get_props(addr)
   1231 	void *addr;
   1232 {
   1233 	return (AUDIO_PROP_MMAP | AUDIO_PROP_FULLDUPLEX);
   1234 }
   1235