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