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