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