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