eap.c revision 1.9 1 /* $NetBSD: eap.c,v 1.9 1998/08/09 20:32:34 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 #endif
762
763 DPRINTFN(1, ("eap_trigger_output: sc=%p start=%p end=%d blksize=%d intr=%p(%p)\n",
764 addr, start, end, blksize, intr, arg));
765 sc->sc_pintr = intr;
766 sc->sc_parg = arg;
767
768 mode = EREAD4(sc, EAP_SIC) & ~(EAP_P2_S_EB | EAP_P2_S_MB | EAP_INC_BITS);
769 mode |= EAP_SET_P2_ST_INC(0) | EAP_SET_P2_END_INC(param->precision * param->factor / 8);
770 sampshift = 0;
771 if (param->precision * param->factor == 16) {
772 mode |= EAP_P2_S_EB;
773 sampshift++;
774 }
775 if (param->channels == 2) {
776 mode |= EAP_P2_S_MB;
777 sampshift++;
778 }
779 EWRITE4(sc, EAP_SIC, mode);
780
781 for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
782 ;
783 if (!p) {
784 printf("eap_trigger_output: bad addr %p\n", start);
785 return (EINVAL);
786 }
787
788 DPRINTF(("eap_trigger_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
789 (int)DMAADDR(p), EAP_SET_SIZE(0, ((end - start) >> 2) - 1)));
790 EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
791 EWRITE4(sc, EAP_DAC2_ADDR, DMAADDR(p));
792 EWRITE4(sc, EAP_DAC2_SIZE, EAP_SET_SIZE(0, ((end - start) >> 2) - 1));
793
794 EWRITE2(sc, EAP_DAC2_CSR, (blksize >> sampshift) - 1);
795 mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
796 EWRITE4(sc, EAP_ICSC, mode);
797 mode |= EAP_DAC2_EN;
798 EWRITE4(sc, EAP_ICSC, mode);
799 DPRINTFN(1, ("eap_trigger_output: set ICSC = 0x%08x\n", mode));
800
801 #ifdef DIAGNOSTIC
802 sc->sc_prun = 1;
803 #endif
804
805 return (0);
806 }
807
808 int
809 eap_trigger_input(addr, start, end, blksize, intr, arg, param)
810 void *addr;
811 void *start, *end;
812 int blksize;
813 void (*intr) __P((void *));
814 void *arg;
815 struct audio_params *param;
816 {
817 struct eap_softc *sc = addr;
818 struct eap_dma *p;
819 u_int32_t mode;
820 int sampshift;
821
822 #ifdef DIAGNOSTIC
823 if (sc->sc_rrun)
824 panic("eap_trigger_input: already running");
825 #endif
826
827 DPRINTFN(1, ("eap_trigger_input: sc=%p start=%p end=%d blksize=%d intr=%p(%p)\n",
828 addr, start, end, blksize, intr, arg));
829 sc->sc_rintr = intr;
830 sc->sc_rarg = arg;
831
832 mode = EREAD4(sc, EAP_SIC) & ~(EAP_R1_S_EB | EAP_R1_S_MB);
833 sampshift = 0;
834 if (param->precision * param->factor == 16) {
835 mode |= EAP_R1_S_EB;
836 sampshift++;
837 }
838 if (param->channels == 2) {
839 mode |= EAP_R1_S_MB;
840 sampshift++;
841 }
842 EWRITE4(sc, EAP_SIC, mode);
843
844 for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
845 ;
846 if (!p) {
847 printf("eap_trigger_input: bad addr %p\n", start);
848 return (EINVAL);
849 }
850
851 DPRINTF(("eap_trigger_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
852 (int)DMAADDR(p), EAP_SET_SIZE(0, ((end - start) >> 2) - 1)));
853 EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
854 EWRITE4(sc, EAP_ADC_ADDR, DMAADDR(p));
855 EWRITE4(sc, EAP_ADC_SIZE, EAP_SET_SIZE(0, ((end - start) >> 2) - 1));
856
857 EWRITE2(sc, EAP_ADC_CSR, (blksize >> sampshift) - 1);
858 mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
859 EWRITE4(sc, EAP_ICSC, mode);
860 mode |= EAP_ADC_EN;
861 EWRITE4(sc, EAP_ICSC, mode);
862 DPRINTFN(1, ("eap_trigger_input: set ICSC = 0x%08x\n", mode));
863
864 #ifdef DIAGNOSTIC
865 sc->sc_rrun = 1;
866 #endif
867
868 return (0);
869 }
870
871 int
872 eap_halt_output(addr)
873 void *addr;
874 {
875 struct eap_softc *sc = addr;
876 u_int32_t mode;
877
878 DPRINTF(("eap: eap_halt_output\n"));
879 mode = EREAD4(sc, EAP_ICSC) & ~EAP_DAC2_EN;
880 EWRITE4(sc, EAP_ICSC, mode);
881 #ifdef DIAGNOSTIC
882 sc->sc_prun = 0;
883 #endif
884 return (0);
885 }
886
887 int
888 eap_halt_input(addr)
889 void *addr;
890 {
891 struct eap_softc *sc = addr;
892 u_int32_t mode;
893
894 DPRINTF(("eap: eap_halt_input\n"));
895 mode = EREAD4(sc, EAP_ICSC) & ~EAP_ADC_EN;
896 EWRITE4(sc, EAP_ICSC, mode);
897 #ifdef DIAGNOSTIC
898 sc->sc_rrun = 0;
899 #endif
900 return (0);
901 }
902
903 int
904 eap_getdev(addr, retp)
905 void *addr;
906 struct audio_device *retp;
907 {
908 *retp = eap_device;
909 return (0);
910 }
911
912 void
913 eap_set_mixer(sc, a, d)
914 struct eap_softc *sc;
915 int a, d;
916 {
917 eap_write_codec(sc, a, d);
918 DPRINTFN(1, ("eap_mixer_set_port port 0x%02x = 0x%02x\n", a, d));
919 }
920
921
922 int
923 eap_mixer_set_port(addr, cp)
924 void *addr;
925 mixer_ctrl_t *cp;
926 {
927 struct eap_softc *sc = addr;
928 int lval, rval, l, r, la, ra;
929 int l1, r1, l2, r2, m, o1, o2;
930
931 if (cp->dev == EAP_RECORD_SOURCE) {
932 if (cp->type != AUDIO_MIXER_SET)
933 return (EINVAL);
934 m = sc->sc_record_source = cp->un.mask;
935 l1 = l2 = r1 = r2 = 0;
936 if (m & (1 << EAP_VOICE_VOL))
937 l2 |= AK_M_VOICE, r2 |= AK_M_VOICE;
938 if (m & (1 << EAP_FM_VOL))
939 l1 |= AK_M_FM_L, r1 |= AK_M_FM_R;
940 if (m & (1 << EAP_CD_VOL))
941 l1 |= AK_M_CD_L, r1 |= AK_M_CD_R;
942 if (m & (1 << EAP_LINE_VOL))
943 l1 |= AK_M_LINE_L, r1 |= AK_M_LINE_R;
944 if (m & (1 << EAP_AUX_VOL))
945 l2 |= AK_M2_AUX_L, r2 |= AK_M2_AUX_R;
946 if (m & (1 << EAP_MIC_VOL))
947 l2 |= AK_M_TMIC, r2 |= AK_M_TMIC;
948 eap_set_mixer(sc, AK_IN_MIXER1_L, l1);
949 eap_set_mixer(sc, AK_IN_MIXER1_R, r1);
950 eap_set_mixer(sc, AK_IN_MIXER2_L, l2);
951 eap_set_mixer(sc, AK_IN_MIXER2_R, r2);
952 return (0);
953 }
954 if (cp->dev == EAP_OUTPUT_SELECT) {
955 if (cp->type != AUDIO_MIXER_SET)
956 return (EINVAL);
957 m = sc->sc_output_source = cp->un.mask;
958 o1 = o2 = 0;
959 if (m & (1 << EAP_VOICE_VOL))
960 o2 |= AK_M_VOICE_L | AK_M_VOICE_R;
961 if (m & (1 << EAP_FM_VOL))
962 o1 |= AK_M_FM_L | AK_M_FM_R;
963 if (m & (1 << EAP_CD_VOL))
964 o1 |= AK_M_CD_L | AK_M_CD_R;
965 if (m & (1 << EAP_LINE_VOL))
966 o1 |= AK_M_LINE_L | AK_M_LINE_R;
967 if (m & (1 << EAP_AUX_VOL))
968 o2 |= AK_M_AUX_L | AK_M_AUX_R;
969 if (m & (1 << EAP_MIC_VOL))
970 o1 |= AK_M_MIC;
971 eap_set_mixer(sc, AK_OUT_MIXER1, o1);
972 eap_set_mixer(sc, AK_OUT_MIXER2, o2);
973 return (0);
974 }
975 if (cp->type != AUDIO_MIXER_VALUE)
976 return (EINVAL);
977 if (cp->un.value.num_channels == 1)
978 lval = rval = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
979 else if (cp->un.value.num_channels == 2) {
980 lval = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
981 rval = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
982 } else
983 return (EINVAL);
984 ra = -1;
985 switch (cp->dev) {
986 case EAP_MASTER_VOL:
987 l = VOL_TO_ATT5(lval);
988 r = VOL_TO_ATT5(rval);
989 la = AK_MASTER_L;
990 ra = AK_MASTER_R;
991 break;
992 case EAP_MIC_VOL:
993 if (cp->un.value.num_channels != 1)
994 return (EINVAL);
995 la = AK_MIC;
996 goto lr;
997 case EAP_VOICE_VOL:
998 la = AK_VOICE_L;
999 ra = AK_VOICE_R;
1000 goto lr;
1001 case EAP_FM_VOL:
1002 la = AK_FM_L;
1003 ra = AK_FM_R;
1004 goto lr;
1005 case EAP_CD_VOL:
1006 la = AK_CD_L;
1007 ra = AK_CD_R;
1008 goto lr;
1009 case EAP_LINE_VOL:
1010 la = AK_LINE_L;
1011 ra = AK_LINE_R;
1012 goto lr;
1013 case EAP_AUX_VOL:
1014 la = AK_AUX_L;
1015 ra = AK_AUX_R;
1016 lr:
1017 l = VOL_TO_GAIN5(lval);
1018 r = VOL_TO_GAIN5(rval);
1019 break;
1020 default:
1021 return (EINVAL);
1022 }
1023 eap_set_mixer(sc, la, l);
1024 sc->sc_port[la] = l;
1025 if (ra >= 0) {
1026 eap_set_mixer(sc, ra, r);
1027 sc->sc_port[ra] = r;
1028 }
1029 return (0);
1030 }
1031
1032 int
1033 eap_mixer_get_port(addr, cp)
1034 void *addr;
1035 mixer_ctrl_t *cp;
1036 {
1037 struct eap_softc *sc = addr;
1038 int la, ra, l, r;
1039
1040 switch (cp->dev) {
1041 case EAP_RECORD_SOURCE:
1042 cp->un.mask = sc->sc_record_source;
1043 return (0);
1044 case EAP_OUTPUT_SELECT:
1045 cp->un.mask = sc->sc_output_source;
1046 return (0);
1047 case EAP_MASTER_VOL:
1048 l = ATT5_TO_VOL(sc->sc_port[AK_MASTER_L]);
1049 r = ATT5_TO_VOL(sc->sc_port[AK_MASTER_R]);
1050 break;
1051 case EAP_MIC_VOL:
1052 if (cp->un.value.num_channels != 1)
1053 return (EINVAL);
1054 la = ra = AK_MIC;
1055 goto lr;
1056 case EAP_VOICE_VOL:
1057 la = AK_VOICE_L;
1058 ra = AK_VOICE_R;
1059 goto lr;
1060 case EAP_FM_VOL:
1061 la = AK_FM_L;
1062 ra = AK_FM_R;
1063 goto lr;
1064 case EAP_CD_VOL:
1065 la = AK_CD_L;
1066 ra = AK_CD_R;
1067 goto lr;
1068 case EAP_LINE_VOL:
1069 la = AK_LINE_L;
1070 ra = AK_LINE_R;
1071 goto lr;
1072 case EAP_AUX_VOL:
1073 la = AK_AUX_L;
1074 ra = AK_AUX_R;
1075 lr:
1076 l = GAIN5_TO_VOL(sc->sc_port[la]);
1077 r = GAIN5_TO_VOL(sc->sc_port[ra]);
1078 break;
1079 default:
1080 return (EINVAL);
1081 }
1082 if (cp->un.value.num_channels == 1)
1083 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
1084 else if (cp->un.value.num_channels == 2) {
1085 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
1086 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
1087 }
1088 return (0);
1089 }
1090
1091 int
1092 eap_query_devinfo(addr, dip)
1093 void *addr;
1094 mixer_devinfo_t *dip;
1095 {
1096 switch (dip->index) {
1097 case EAP_MASTER_VOL:
1098 dip->type = AUDIO_MIXER_VALUE;
1099 dip->mixer_class = EAP_OUTPUT_CLASS;
1100 dip->prev = dip->next = AUDIO_MIXER_LAST;
1101 strcpy(dip->label.name, AudioNmaster);
1102 dip->un.v.num_channels = 2;
1103 strcpy(dip->un.v.units.name, AudioNvolume);
1104 return (0);
1105 case EAP_VOICE_VOL:
1106 dip->type = AUDIO_MIXER_VALUE;
1107 dip->mixer_class = EAP_INPUT_CLASS;
1108 dip->prev = AUDIO_MIXER_LAST;
1109 dip->next = AUDIO_MIXER_LAST;
1110 strcpy(dip->label.name, AudioNdac);
1111 dip->un.v.num_channels = 2;
1112 strcpy(dip->un.v.units.name, AudioNvolume);
1113 return (0);
1114 case EAP_FM_VOL:
1115 dip->type = AUDIO_MIXER_VALUE;
1116 dip->mixer_class = EAP_INPUT_CLASS;
1117 dip->prev = AUDIO_MIXER_LAST;
1118 dip->next = AUDIO_MIXER_LAST;
1119 strcpy(dip->label.name, AudioNfmsynth);
1120 dip->un.v.num_channels = 2;
1121 strcpy(dip->un.v.units.name, AudioNvolume);
1122 return (0);
1123 case EAP_CD_VOL:
1124 dip->type = AUDIO_MIXER_VALUE;
1125 dip->mixer_class = EAP_INPUT_CLASS;
1126 dip->prev = AUDIO_MIXER_LAST;
1127 dip->next = AUDIO_MIXER_LAST;
1128 strcpy(dip->label.name, AudioNcd);
1129 dip->un.v.num_channels = 2;
1130 strcpy(dip->un.v.units.name, AudioNvolume);
1131 return (0);
1132 case EAP_LINE_VOL:
1133 dip->type = AUDIO_MIXER_VALUE;
1134 dip->mixer_class = EAP_INPUT_CLASS;
1135 dip->prev = AUDIO_MIXER_LAST;
1136 dip->next = AUDIO_MIXER_LAST;
1137 strcpy(dip->label.name, AudioNline);
1138 dip->un.v.num_channels = 2;
1139 strcpy(dip->un.v.units.name, AudioNvolume);
1140 return (0);
1141 case EAP_AUX_VOL:
1142 dip->type = AUDIO_MIXER_VALUE;
1143 dip->mixer_class = EAP_INPUT_CLASS;
1144 dip->prev = AUDIO_MIXER_LAST;
1145 dip->next = AUDIO_MIXER_LAST;
1146 strcpy(dip->label.name, AudioNaux);
1147 dip->un.v.num_channels = 2;
1148 strcpy(dip->un.v.units.name, AudioNvolume);
1149 return (0);
1150 case EAP_MIC_VOL:
1151 dip->type = AUDIO_MIXER_VALUE;
1152 dip->mixer_class = EAP_INPUT_CLASS;
1153 dip->prev = AUDIO_MIXER_LAST;
1154 dip->next = AUDIO_MIXER_LAST;
1155 strcpy(dip->label.name, AudioNmicrophone);
1156 dip->un.v.num_channels = 1;
1157 strcpy(dip->un.v.units.name, AudioNvolume);
1158 return (0);
1159 case EAP_RECORD_SOURCE:
1160 dip->mixer_class = EAP_RECORD_CLASS;
1161 dip->prev = dip->next = AUDIO_MIXER_LAST;
1162 strcpy(dip->label.name, AudioNsource);
1163 dip->type = AUDIO_MIXER_SET;
1164 dip->un.s.num_mem = 6;
1165 strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1166 dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1167 strcpy(dip->un.s.member[1].label.name, AudioNcd);
1168 dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1169 strcpy(dip->un.s.member[2].label.name, AudioNline);
1170 dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1171 strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1172 dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1173 strcpy(dip->un.s.member[4].label.name, AudioNaux);
1174 dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1175 strcpy(dip->un.s.member[5].label.name, AudioNdac);
1176 dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1177 return (0);
1178 case EAP_OUTPUT_SELECT:
1179 dip->mixer_class = EAP_OUTPUT_CLASS;
1180 dip->prev = dip->next = AUDIO_MIXER_LAST;
1181 strcpy(dip->label.name, AudioNselect);
1182 dip->type = AUDIO_MIXER_SET;
1183 dip->un.s.num_mem = 6;
1184 strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1185 dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1186 strcpy(dip->un.s.member[1].label.name, AudioNcd);
1187 dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1188 strcpy(dip->un.s.member[2].label.name, AudioNline);
1189 dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1190 strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1191 dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1192 strcpy(dip->un.s.member[4].label.name, AudioNaux);
1193 dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1194 strcpy(dip->un.s.member[5].label.name, AudioNdac);
1195 dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1196 return (0);
1197 case EAP_OUTPUT_CLASS:
1198 dip->type = AUDIO_MIXER_CLASS;
1199 dip->mixer_class = EAP_OUTPUT_CLASS;
1200 dip->next = dip->prev = AUDIO_MIXER_LAST;
1201 strcpy(dip->label.name, AudioCoutputs);
1202 return (0);
1203 case EAP_RECORD_CLASS:
1204 dip->type = AUDIO_MIXER_CLASS;
1205 dip->mixer_class = EAP_RECORD_CLASS;
1206 dip->next = dip->prev = AUDIO_MIXER_LAST;
1207 strcpy(dip->label.name, AudioCrecord);
1208 return (0);
1209 case EAP_INPUT_CLASS:
1210 dip->type = AUDIO_MIXER_CLASS;
1211 dip->mixer_class = EAP_INPUT_CLASS;
1212 dip->next = dip->prev = AUDIO_MIXER_LAST;
1213 strcpy(dip->label.name, AudioCinputs);
1214 return (0);
1215 }
1216 return (ENXIO);
1217 }
1218
1219 void *
1220 eap_malloc(addr, size, pool, flags)
1221 void *addr;
1222 u_long size;
1223 int pool;
1224 int flags;
1225 {
1226 struct eap_softc *sc = addr;
1227 struct eap_dma *p;
1228 int error;
1229
1230 p = malloc(sizeof(*p), pool, flags);
1231 if (!p)
1232 return (0);
1233 error = eap_allocmem(sc, size, 16, p);
1234 if (error) {
1235 free(p, pool);
1236 return (0);
1237 }
1238 p->next = sc->sc_dmas;
1239 sc->sc_dmas = p;
1240 return (KERNADDR(p));
1241 }
1242
1243 void
1244 eap_free(addr, ptr, pool)
1245 void *addr;
1246 void *ptr;
1247 int pool;
1248 {
1249 struct eap_softc *sc = addr;
1250 struct eap_dma **p;
1251
1252 for (p = &sc->sc_dmas; *p; p = &(*p)->next) {
1253 if (KERNADDR(*p) == ptr) {
1254 eap_freemem(sc, *p);
1255 *p = (*p)->next;
1256 free(*p, pool);
1257 return;
1258 }
1259 }
1260 }
1261
1262 u_long
1263 eap_round(addr, size)
1264 void *addr;
1265 u_long size;
1266 {
1267 return (size);
1268 }
1269
1270 int
1271 eap_mappage(addr, mem, off, prot)
1272 void *addr;
1273 void *mem;
1274 int off;
1275 int prot;
1276 {
1277 struct eap_softc *sc = addr;
1278 struct eap_dma *p;
1279
1280 for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
1281 ;
1282 if (!p)
1283 return (-1);
1284 return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
1285 off, prot, BUS_DMA_WAITOK));
1286 }
1287
1288 int
1289 eap_get_props(addr)
1290 void *addr;
1291 {
1292 return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX);
1293 }
1294