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