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