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