eap.c revision 1.74.2.2 1 /* $NetBSD: eap.c,v 1.74.2.2 2005/01/09 08:42:46 kent Exp $ */
2 /* $OpenBSD: eap.c,v 1.6 1999/10/05 19:24:42 csapuntz Exp $ */
3
4 /*
5 * Copyright (c) 1998, 1999, 2002 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson <augustss (at) NetBSD.org>, Charles M. Hannum, and
10 * Antti Kantee <pooka (at) NetBSD.org>.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 /*
42 * Debugging: Andreas Gustafsson <gson (at) araneus.fi>
43 * Testing: Chuck Cranor <chuck (at) maria.wustl.edu>
44 * Phil Nelson <phil (at) cs.wwu.edu>
45 *
46 * ES1371/AC97: Ezra Story <ezy (at) panix.com>
47 */
48
49 /*
50 * Ensoniq ES1370 + AK4531 and ES1371/ES1373 + AC97
51 *
52 * Documentation links:
53 *
54 * ftp://ftp.alsa-project.org/pub/manuals/ensoniq/
55 * ftp://ftp.alsa-project.org/pub/manuals/asahi_kasei/4531.pdf
56 * ftp://download.intel.com/ial/scalableplatforms/audio/ac97r21.pdf
57 */
58
59 #include <sys/cdefs.h>
60 __KERNEL_RCSID(0, "$NetBSD: eap.c,v 1.74.2.2 2005/01/09 08:42:46 kent Exp $");
61
62 #include "midi.h"
63 #include "joy_eap.h"
64
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/fcntl.h>
69 #include <sys/malloc.h>
70 #include <sys/device.h>
71 #include <sys/proc.h>
72 #include <sys/select.h>
73
74 #include <dev/pci/pcidevs.h>
75 #include <dev/pci/pcivar.h>
76
77 #include <sys/audioio.h>
78 #include <dev/audio_if.h>
79 #include <dev/midi_if.h>
80 #include <dev/audiovar.h>
81 #include <dev/mulaw.h>
82 #include <dev/auconv.h>
83 #include <dev/ic/ac97var.h>
84
85 #include <machine/bus.h>
86
87 #include <dev/pci/eapreg.h>
88 #include <dev/pci/eapvar.h>
89
90 #define PCI_CBIO 0x10
91
92 /* Debug */
93 #ifdef AUDIO_DEBUG
94 #define DPRINTF(x) if (eapdebug) printf x
95 #define DPRINTFN(n,x) if (eapdebug>(n)) printf x
96 int eapdebug = 0;
97 #else
98 #define DPRINTF(x)
99 #define DPRINTFN(n,x)
100 #endif
101
102 int eap_match(struct device *, struct cfdata *, void *);
103 void eap_attach(struct device *, struct device *, void *);
104 int eap_detach(struct device *, int);
105 int eap_intr(void *);
106
107 struct eap_dma {
108 bus_dmamap_t map;
109 caddr_t addr;
110 bus_dma_segment_t segs[1];
111 int nsegs;
112 size_t size;
113 struct eap_dma *next;
114 };
115
116 #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
117 #define KERNADDR(p) ((void *)((p)->addr))
118
119 /*
120 * The card has two DACs. Using them is a bit twisted: we use DAC2
121 * as default and DAC1 as the optional secondary DAC.
122 */
123 #define EAP_DAC1 1
124 #define EAP_DAC2 0
125 #define EAP_I1 EAP_DAC2
126 #define EAP_I2 EAP_DAC1
127 struct eap_instance {
128 struct device *parent;
129 int index;
130
131 void (*ei_pintr)(void *); /* DMA completion intr handler */
132 void *ei_parg; /* arg for ei_intr() */
133 struct device *ei_audiodev; /* audio device, for detach */
134 #ifdef DIAGNOSTIC
135 char ei_prun;
136 #endif
137 };
138
139 struct eap_softc {
140 struct device sc_dev; /* base device */
141 void *sc_ih; /* interrupt vectoring */
142 bus_space_tag_t iot;
143 bus_space_handle_t ioh;
144 bus_size_t iosz;
145 bus_dma_tag_t sc_dmatag; /* DMA tag */
146
147 struct eap_dma *sc_dmas;
148
149 void (*sc_rintr)(void *); /* DMA completion intr handler */
150 void *sc_rarg; /* arg for sc_intr() */
151 #ifdef DIAGNOSTIC
152 char sc_rrun;
153 #endif
154
155 #if NMIDI > 0
156 void (*sc_iintr)(void *, int); /* midi input ready handler */
157 void (*sc_ointr)(void *); /* midi output ready handler */
158 void *sc_arg;
159 struct device *sc_mididev;
160 #endif
161 #if NJOY_EAP > 0
162 struct device *sc_gameport;
163 #endif
164
165 u_short sc_port[AK_NPORTS]; /* mirror of the hardware setting */
166 u_int sc_record_source; /* recording source mask */
167 u_int sc_output_source; /* output source mask */
168 u_int sc_mic_preamp;
169 char sc_1371; /* Using ES1371/AC97 codec */
170
171 struct ac97_codec_if *codec_if;
172 struct ac97_host_if host_if;
173
174 struct eap_instance sc_ei[2];
175
176 pci_chipset_tag_t sc_pc; /* For detach */
177 };
178
179 int eap_allocmem(struct eap_softc *, size_t, size_t, struct eap_dma *);
180 int eap_freemem(struct eap_softc *, struct eap_dma *);
181
182 #define EWRITE1(sc, r, x) bus_space_write_1((sc)->iot, (sc)->ioh, (r), (x))
183 #define EWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
184 #define EWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
185 #define EREAD1(sc, r) bus_space_read_1((sc)->iot, (sc)->ioh, (r))
186 #define EREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
187 #define EREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
188
189 CFATTACH_DECL(eap, sizeof(struct eap_softc),
190 eap_match, eap_attach, eap_detach, NULL);
191
192 int eap_open(void *, int);
193 int eap_query_encoding(void *, struct audio_encoding *);
194 int eap_set_params(void *, int, int, audio_params_t *, audio_params_t *,
195 stream_filter_list_t *, stream_filter_list_t *);
196 int eap_round_blocksize(void *, int, int, const audio_params_t *);
197 int eap_trigger_output(void *, void *, void *, int, void (*)(void *),
198 void *, const audio_params_t *);
199 int eap_trigger_input(void *, void *, void *, int, void (*)(void *),
200 void *, const audio_params_t *);
201 int eap_halt_output(void *);
202 int eap_halt_input(void *);
203 void eap1370_write_codec(struct eap_softc *, int, int);
204 int eap_getdev(void *, struct audio_device *);
205 int eap1370_mixer_set_port(void *, mixer_ctrl_t *);
206 int eap1370_mixer_get_port(void *, mixer_ctrl_t *);
207 int eap1371_mixer_set_port(void *, mixer_ctrl_t *);
208 int eap1371_mixer_get_port(void *, mixer_ctrl_t *);
209 int eap1370_query_devinfo(void *, mixer_devinfo_t *);
210 void *eap_malloc(void *, int, size_t, struct malloc_type *, int);
211 void eap_free(void *, void *, struct malloc_type *);
212 size_t eap_round_buffersize(void *, int, size_t);
213 paddr_t eap_mappage(void *, void *, off_t, int);
214 int eap_get_props(void *);
215 void eap1370_set_mixer(struct eap_softc *sc, int a, int d);
216 u_int32_t eap1371_src_wait(struct eap_softc *sc);
217 void eap1371_set_adc_rate(struct eap_softc *sc, int rate);
218 void eap1371_set_dac_rate(struct eap_instance *ei, int rate);
219 int eap1371_src_read(struct eap_softc *sc, int a);
220 void eap1371_src_write(struct eap_softc *sc, int a, int d);
221 int eap1371_query_devinfo(void *addr, mixer_devinfo_t *dip);
222
223 int eap1371_attach_codec(void *sc, struct ac97_codec_if *);
224 int eap1371_read_codec(void *sc, u_int8_t a, u_int16_t *d);
225 int eap1371_write_codec(void *sc, u_int8_t a, u_int16_t d);
226 int eap1371_reset_codec(void *sc);
227 int eap1371_get_portnum_by_name(struct eap_softc *, char *, char *,
228 char *);
229 #if NMIDI > 0
230 void eap_midi_close(void *);
231 void eap_midi_getinfo(void *, struct midi_info *);
232 int eap_midi_open(void *, int, void (*)(void *, int),
233 void (*)(void *), void *);
234 int eap_midi_output(void *, int);
235 #endif
236
237 const struct audio_hw_if eap1370_hw_if = {
238 eap_open,
239 NULL, /* close */
240 NULL,
241 eap_query_encoding,
242 eap_set_params,
243 eap_round_blocksize,
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 NULL,
249 eap_halt_output,
250 eap_halt_input,
251 NULL,
252 eap_getdev,
253 NULL,
254 eap1370_mixer_set_port,
255 eap1370_mixer_get_port,
256 eap1370_query_devinfo,
257 eap_malloc,
258 eap_free,
259 eap_round_buffersize,
260 eap_mappage,
261 eap_get_props,
262 eap_trigger_output,
263 eap_trigger_input,
264 NULL,
265 };
266
267 const struct audio_hw_if eap1371_hw_if = {
268 eap_open,
269 NULL, /* close */
270 NULL,
271 eap_query_encoding,
272 eap_set_params,
273 eap_round_blocksize,
274 NULL,
275 NULL,
276 NULL,
277 NULL,
278 NULL,
279 eap_halt_output,
280 eap_halt_input,
281 NULL,
282 eap_getdev,
283 NULL,
284 eap1371_mixer_set_port,
285 eap1371_mixer_get_port,
286 eap1371_query_devinfo,
287 eap_malloc,
288 eap_free,
289 eap_round_buffersize,
290 eap_mappage,
291 eap_get_props,
292 eap_trigger_output,
293 eap_trigger_input,
294 NULL,
295 };
296
297 #if NMIDI > 0
298 const struct midi_hw_if eap_midi_hw_if = {
299 eap_midi_open,
300 eap_midi_close,
301 eap_midi_output,
302 eap_midi_getinfo,
303 0, /* ioctl */
304 };
305 #endif
306
307 struct audio_device eap_device = {
308 "Ensoniq AudioPCI",
309 "",
310 "eap"
311 };
312
313 #define EAP_NFORMATS 4
314 static const struct audio_format eap_formats[EAP_NFORMATS] = {
315 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
316 2, AUFMT_STEREO, 0, {4000, 48000}},
317 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
318 1, AUFMT_MONAURAL, 0, {4000, 48000}},
319 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8,
320 2, AUFMT_STEREO, 0, {4000, 48000}},
321 {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8,
322 1, AUFMT_MONAURAL, 0, {4000, 48000}},
323 };
324
325 int
326 eap_match(struct device *parent, struct cfdata *match, void *aux)
327 {
328 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
329
330 switch (PCI_VENDOR(pa->pa_id)) {
331 case PCI_VENDOR_CREATIVELABS:
332 switch (PCI_PRODUCT(pa->pa_id)) {
333 case PCI_PRODUCT_CREATIVELABS_EV1938:
334 return (1);
335 }
336 break;
337 case PCI_VENDOR_ENSONIQ:
338 switch (PCI_PRODUCT(pa->pa_id)) {
339 case PCI_PRODUCT_ENSONIQ_AUDIOPCI:
340 case PCI_PRODUCT_ENSONIQ_AUDIOPCI97:
341 case PCI_PRODUCT_ENSONIQ_CT5880:
342 return (1);
343 }
344 break;
345 }
346
347 return (0);
348 }
349
350 void
351 eap1370_write_codec(struct eap_softc *sc, int a, int d)
352 {
353 int icss, to;
354
355 to = EAP_WRITE_TIMEOUT;
356 do {
357 icss = EREAD4(sc, EAP_ICSS);
358 DPRINTFN(5,("eap: codec %d prog: icss=0x%08x\n", a, icss));
359 if (!to--) {
360 printf("eap: timeout writing to codec\n");
361 return;
362 }
363 } while(icss & EAP_CWRIP); /* XXX could use CSTAT here */
364 EWRITE4(sc, EAP_CODEC, EAP_SET_CODEC(a, d));
365 }
366
367 /*
368 * Reading and writing the CODEC is very convoluted. This mimics the
369 * FreeBSD and Linux drivers.
370 */
371
372 static __inline void
373 eap1371_ready_codec(struct eap_softc *sc, u_int8_t a, u_int32_t wd)
374 {
375 int to, s;
376 u_int32_t src, t;
377
378 for (to = 0; to < EAP_WRITE_TIMEOUT; to++) {
379 if (!(EREAD4(sc, E1371_CODEC) & E1371_CODEC_WIP))
380 break;
381 delay(1);
382 }
383 if (to >= EAP_WRITE_TIMEOUT)
384 printf("%s: eap1371_ready_codec timeout 1\n",
385 sc->sc_dev.dv_xname);
386
387 s = splaudio();
388 src = eap1371_src_wait(sc) & E1371_SRC_CTLMASK;
389 EWRITE4(sc, E1371_SRC, src | E1371_SRC_STATE_OK);
390
391 for (to = 0; to < EAP_READ_TIMEOUT; to++) {
392 t = EREAD4(sc, E1371_SRC);
393 if ((t & E1371_SRC_STATE_MASK) == 0)
394 break;
395 delay(1);
396 }
397 if (to >= EAP_READ_TIMEOUT)
398 printf("%s: eap1371_ready_codec timeout 2\n",
399 sc->sc_dev.dv_xname);
400
401 for (to = 0; to < EAP_READ_TIMEOUT; to++) {
402 t = EREAD4(sc, E1371_SRC);
403 if ((t & E1371_SRC_STATE_MASK) == E1371_SRC_STATE_OK)
404 break;
405 delay(1);
406 }
407 if (to >= EAP_READ_TIMEOUT)
408 printf("%s: eap1371_ready_codec timeout 3\n",
409 sc->sc_dev.dv_xname);
410
411 EWRITE4(sc, E1371_CODEC, wd);
412
413 eap1371_src_wait(sc);
414 EWRITE4(sc, E1371_SRC, src);
415
416 splx(s);
417 }
418
419 int
420 eap1371_read_codec(void *sc_, u_int8_t a, u_int16_t *d)
421 {
422 struct eap_softc *sc = sc_;
423 int to;
424 u_int32_t t;
425
426 eap1371_ready_codec(sc, a, E1371_SET_CODEC(a, 0) | E1371_CODEC_READ);
427
428 for (to = 0; to < EAP_WRITE_TIMEOUT; to++) {
429 if (!(EREAD4(sc, E1371_CODEC) & E1371_CODEC_WIP))
430 break;
431 }
432 if (to > EAP_WRITE_TIMEOUT)
433 printf("%s: eap1371_read_codec timeout 1\n",
434 sc->sc_dev.dv_xname);
435
436 for (to = 0; to < EAP_WRITE_TIMEOUT; to++) {
437 t = EREAD4(sc, E1371_CODEC);
438 if (t & E1371_CODEC_VALID)
439 break;
440 }
441 if (to > EAP_WRITE_TIMEOUT)
442 printf("%s: eap1371_read_codec timeout 2\n",
443 sc->sc_dev.dv_xname);
444
445 *d = (u_int16_t)t;
446
447 DPRINTFN(10, ("eap1371: reading codec (%x) = %x\n", a, *d));
448
449 return (0);
450 }
451
452 int
453 eap1371_write_codec(void *sc_, u_int8_t a, u_int16_t d)
454 {
455 struct eap_softc *sc = sc_;
456
457 eap1371_ready_codec(sc, a, E1371_SET_CODEC(a, d));
458
459 DPRINTFN(10, ("eap1371: writing codec %x --> %x\n", d, a));
460
461 return (0);
462 }
463
464 u_int32_t
465 eap1371_src_wait(struct eap_softc *sc)
466 {
467 int to;
468 u_int32_t src;
469
470 for (to = 0; to < EAP_READ_TIMEOUT; to++) {
471 src = EREAD4(sc, E1371_SRC);
472 if (!(src & E1371_SRC_RBUSY))
473 return (src);
474 delay(1);
475 }
476 printf("%s: eap1371_src_wait timeout\n", sc->sc_dev.dv_xname);
477 return (src);
478 }
479
480 int
481 eap1371_src_read(struct eap_softc *sc, int a)
482 {
483 int to;
484 u_int32_t src, t;
485
486 src = eap1371_src_wait(sc) & E1371_SRC_CTLMASK;
487 src |= E1371_SRC_ADDR(a);
488 EWRITE4(sc, E1371_SRC, src | E1371_SRC_STATE_OK);
489
490 t = eap1371_src_wait(sc);
491 if ((t & E1371_SRC_STATE_MASK) != E1371_SRC_STATE_OK) {
492 for (to = 0; to < EAP_READ_TIMEOUT; to++) {
493 t = EREAD4(sc, E1371_SRC);
494 if ((t & E1371_SRC_STATE_MASK) == E1371_SRC_STATE_OK)
495 break;
496 delay(1);
497 }
498 }
499
500 EWRITE4(sc, E1371_SRC, src);
501
502 return t & E1371_SRC_DATAMASK;
503 }
504
505 void
506 eap1371_src_write(struct eap_softc *sc, int a, int d)
507 {
508 u_int32_t r;
509
510 r = eap1371_src_wait(sc) & E1371_SRC_CTLMASK;
511 r |= E1371_SRC_RAMWE | E1371_SRC_ADDR(a) | E1371_SRC_DATA(d);
512 EWRITE4(sc, E1371_SRC, r);
513 }
514
515 void
516 eap1371_set_adc_rate(struct eap_softc *sc, int rate)
517 {
518 int freq, n, truncm;
519 int out;
520 int s;
521
522 /* Whatever, it works, so I'll leave it :) */
523
524 if (rate > 48000)
525 rate = 48000;
526 if (rate < 4000)
527 rate = 4000;
528 n = rate / 3000;
529 if ((1 << n) & SRC_MAGIC)
530 n--;
531 truncm = ((21 * n) - 1) | 1;
532 freq = ((48000 << 15) / rate) * n;
533 if (rate >= 24000) {
534 if (truncm > 239)
535 truncm = 239;
536 out = ESRC_SET_TRUNC((239 - truncm) / 2);
537 } else {
538 if (truncm > 119)
539 truncm = 119;
540 out = ESRC_SMF | ESRC_SET_TRUNC((119 - truncm) / 2);
541 }
542 out |= ESRC_SET_N(n);
543 s = splaudio();
544 eap1371_src_write(sc, ESRC_ADC+ESRC_TRUNC_N, out);
545
546
547 out = eap1371_src_read(sc, ESRC_ADC+ESRC_IREGS) & 0xff;
548 eap1371_src_write(sc, ESRC_ADC+ESRC_IREGS, out |
549 ESRC_SET_VFI(freq >> 15));
550 eap1371_src_write(sc, ESRC_ADC+ESRC_VFF, freq & 0x7fff);
551 eap1371_src_write(sc, ESRC_ADC_VOLL, ESRC_SET_ADC_VOL(n));
552 eap1371_src_write(sc, ESRC_ADC_VOLR, ESRC_SET_ADC_VOL(n));
553 splx(s);
554 }
555
556 void
557 eap1371_set_dac_rate(struct eap_instance *ei, int rate)
558 {
559 struct eap_softc *sc = (struct eap_softc *)ei->parent;
560 int dac = ei->index == EAP_DAC1 ? ESRC_DAC1 : ESRC_DAC2;
561 int freq, r;
562 int s;
563
564 DPRINTFN(2, ("eap1371_set_dac_date: set rate for %d\n", ei->index));
565
566 /* Whatever, it works, so I'll leave it :) */
567
568 if (rate > 48000)
569 rate = 48000;
570 if (rate < 4000)
571 rate = 4000;
572 freq = ((rate << 15) + 1500) / 3000;
573
574 s = splaudio();
575 eap1371_src_wait(sc);
576 r = EREAD4(sc, E1371_SRC) & (E1371_SRC_DISABLE |
577 E1371_SRC_DISP2 | E1371_SRC_DISP1 | E1371_SRC_DISREC);
578 r |= ei->index == EAP_DAC1 ? E1371_SRC_DISP1 : E1371_SRC_DISP2;
579 EWRITE4(sc, E1371_SRC, r);
580 r = eap1371_src_read(sc, dac + ESRC_IREGS) & 0x00ff;
581 eap1371_src_write(sc, dac + ESRC_IREGS, r | ((freq >> 5) & 0xfc00));
582 eap1371_src_write(sc, dac + ESRC_VFF, freq & 0x7fff);
583 r = EREAD4(sc, E1371_SRC) & (E1371_SRC_DISABLE |
584 E1371_SRC_DISP2 | E1371_SRC_DISP1 | E1371_SRC_DISREC);
585 r &= ~(ei->index == EAP_DAC1 ? E1371_SRC_DISP1 : E1371_SRC_DISP2);
586 EWRITE4(sc, E1371_SRC, r);
587 splx(s);
588 }
589
590 void
591 eap_attach(struct device *parent, struct device *self, void *aux)
592 {
593 struct eap_softc *sc = (struct eap_softc *)self;
594 struct pci_attach_args *pa = (struct pci_attach_args *)aux;
595 pci_chipset_tag_t pc = pa->pa_pc;
596 const struct audio_hw_if *eap_hw_if;
597 char const *intrstr;
598 pci_intr_handle_t ih;
599 pcireg_t csr;
600 char devinfo[256];
601 mixer_ctrl_t ctl;
602 int i;
603 int revision, ct5880;
604 const char *revstr = "";
605 #if NJOY_EAP > 0
606 struct eap_gameport_args gpargs;
607 #endif
608
609 aprint_naive(": Audio controller\n");
610
611 /* Stash this away for detach */
612 sc->sc_pc = pc;
613
614 /* Flag if we're "creative" */
615 sc->sc_1371 = !(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ENSONIQ &&
616 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ENSONIQ_AUDIOPCI);
617
618 /*
619 * The vendor and product ID's are quite "interesting". Just
620 * trust the following and be happy.
621 */
622 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
623 revision = PCI_REVISION(pa->pa_class);
624 ct5880 = 0;
625 if (sc->sc_1371) {
626 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ENSONIQ &&
627 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ENSONIQ_CT5880) {
628 ct5880 = 1;
629 switch (revision) {
630 case EAP_CT5880_C: revstr = "CT5880-C "; break;
631 case EAP_CT5880_D: revstr = "CT5880-D "; break;
632 case EAP_CT5880_E: revstr = "CT5880-E "; break;
633 }
634 } else {
635 switch (revision) {
636 case EAP_EV1938_A: revstr = "EV1938-A "; break;
637 case EAP_ES1373_A: revstr = "ES1373-A "; break;
638 case EAP_ES1373_B: revstr = "ES1373-B "; break;
639 case EAP_CT5880_A: revstr = "CT5880-A "; ct5880=1;break;
640 case EAP_ES1373_8: revstr = "ES1373-8" ; ct5880=1;break;
641 case EAP_ES1371_B: revstr = "ES1371-B "; break;
642 }
643 }
644 }
645 aprint_normal(": %s %s(rev. 0x%02x)\n", devinfo, revstr, revision);
646
647 /* Map I/O register */
648 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
649 &sc->iot, &sc->ioh, NULL, &sc->iosz)) {
650 aprint_error("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
651 return;
652 }
653
654 sc->sc_dmatag = pa->pa_dmat;
655
656 /* Enable the device. */
657 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
658 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
659 csr | PCI_COMMAND_MASTER_ENABLE);
660
661 /* Map and establish the interrupt. */
662 if (pci_intr_map(pa, &ih)) {
663 aprint_error("%s: couldn't map interrupt\n",
664 sc->sc_dev.dv_xname);
665 return;
666 }
667 intrstr = pci_intr_string(pc, ih);
668 sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, eap_intr, sc);
669 if (sc->sc_ih == NULL) {
670 aprint_error("%s: couldn't establish interrupt",
671 sc->sc_dev.dv_xname);
672 if (intrstr != NULL)
673 aprint_normal(" at %s", intrstr);
674 aprint_normal("\n");
675 return;
676 }
677 aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
678
679 sc->sc_ei[EAP_I1].parent = (struct device *)sc;
680 sc->sc_ei[EAP_I1].index = EAP_DAC2;
681 sc->sc_ei[EAP_I2].parent = (struct device *)sc;
682 sc->sc_ei[EAP_I2].index = EAP_DAC1;
683
684 if (!sc->sc_1371) {
685 /* Enable interrupts and looping mode. */
686 /* enable the parts we need */
687 EWRITE4(sc, EAP_SIC, EAP_P2_INTR_EN | EAP_R1_INTR_EN);
688 EWRITE4(sc, EAP_ICSC, EAP_CDC_EN);
689
690 /* reset codec */
691 /* normal operation */
692 /* select codec clocks */
693 eap1370_write_codec(sc, AK_RESET, AK_PD);
694 eap1370_write_codec(sc, AK_RESET, AK_PD | AK_NRST);
695 eap1370_write_codec(sc, AK_CS, 0x0);
696
697 eap_hw_if = &eap1370_hw_if;
698
699 /* Enable all relevant mixer switches. */
700 ctl.dev = EAP_OUTPUT_SELECT;
701 ctl.type = AUDIO_MIXER_SET;
702 ctl.un.mask = 1 << EAP_VOICE_VOL | 1 << EAP_FM_VOL |
703 1 << EAP_CD_VOL | 1 << EAP_LINE_VOL | 1 << EAP_AUX_VOL |
704 1 << EAP_MIC_VOL;
705 eap_hw_if->set_port(&sc->sc_ei[EAP_I1], &ctl);
706
707 ctl.type = AUDIO_MIXER_VALUE;
708 ctl.un.value.num_channels = 1;
709 for (ctl.dev = EAP_MASTER_VOL; ctl.dev < EAP_MIC_VOL;
710 ctl.dev++) {
711 ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = VOL_0DB;
712 eap_hw_if->set_port(&sc->sc_ei[EAP_I1], &ctl);
713 }
714 ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = 0;
715 eap_hw_if->set_port(&sc->sc_ei[EAP_I1], &ctl);
716 ctl.dev = EAP_MIC_PREAMP;
717 ctl.type = AUDIO_MIXER_ENUM;
718 ctl.un.ord = 0;
719 eap_hw_if->set_port(&sc->sc_ei[EAP_I1], &ctl);
720 ctl.dev = EAP_RECORD_SOURCE;
721 ctl.type = AUDIO_MIXER_SET;
722 ctl.un.mask = 1 << EAP_MIC_VOL;
723 eap_hw_if->set_port(&sc->sc_ei[EAP_I1], &ctl);
724 } else {
725 /* clean slate */
726
727 EWRITE4(sc, EAP_SIC, 0);
728 EWRITE4(sc, EAP_ICSC, 0);
729 EWRITE4(sc, E1371_LEGACY, 0);
730
731 if (ct5880) {
732 EWRITE4(sc, EAP_ICSS, EAP_CT5880_AC97_RESET);
733 /* Let codec wake up */
734 delay(20000);
735 }
736
737 /* Reset from es1371's perspective */
738 EWRITE4(sc, EAP_ICSC, E1371_SYNC_RES);
739 delay(20);
740 EWRITE4(sc, EAP_ICSC, 0);
741
742 /*
743 * Must properly reprogram sample rate converter,
744 * or it locks up. Set some defaults for the life of the
745 * machine, and set up a sb default sample rate.
746 */
747 EWRITE4(sc, E1371_SRC, E1371_SRC_DISABLE);
748 for (i = 0; i < 0x80; i++)
749 eap1371_src_write(sc, i, 0);
750 eap1371_src_write(sc, ESRC_DAC1+ESRC_TRUNC_N, ESRC_SET_N(16));
751 eap1371_src_write(sc, ESRC_DAC2+ESRC_TRUNC_N, ESRC_SET_N(16));
752 eap1371_src_write(sc, ESRC_DAC1+ESRC_IREGS, ESRC_SET_VFI(16));
753 eap1371_src_write(sc, ESRC_DAC2+ESRC_IREGS, ESRC_SET_VFI(16));
754 eap1371_src_write(sc, ESRC_ADC_VOLL, ESRC_SET_ADC_VOL(16));
755 eap1371_src_write(sc, ESRC_ADC_VOLR, ESRC_SET_ADC_VOL(16));
756 eap1371_src_write(sc, ESRC_DAC1_VOLL, ESRC_SET_DAC_VOLI(1));
757 eap1371_src_write(sc, ESRC_DAC1_VOLR, ESRC_SET_DAC_VOLI(1));
758 eap1371_src_write(sc, ESRC_DAC2_VOLL, ESRC_SET_DAC_VOLI(1));
759 eap1371_src_write(sc, ESRC_DAC2_VOLR, ESRC_SET_DAC_VOLI(1));
760 eap1371_set_adc_rate(sc, 22050);
761 eap1371_set_dac_rate(&sc->sc_ei[0], 22050);
762 eap1371_set_dac_rate(&sc->sc_ei[1], 22050);
763
764 EWRITE4(sc, E1371_SRC, 0);
765
766 /* Reset codec */
767
768 /* Interrupt enable */
769 sc->host_if.arg = sc;
770 sc->host_if.attach = eap1371_attach_codec;
771 sc->host_if.read = eap1371_read_codec;
772 sc->host_if.write = eap1371_write_codec;
773 sc->host_if.reset = eap1371_reset_codec;
774
775 if (ac97_attach(&sc->host_if, self) == 0) {
776 /* Interrupt enable */
777 EWRITE4(sc, EAP_SIC, EAP_P2_INTR_EN | EAP_R1_INTR_EN);
778 } else
779 return;
780
781 eap_hw_if = &eap1371_hw_if;
782 }
783
784 sc->sc_ei[EAP_I1].ei_audiodev =
785 audio_attach_mi(eap_hw_if, &sc->sc_ei[EAP_I1], &sc->sc_dev);
786
787 #ifdef EAP_USE_BOTH_DACS
788 aprint_normal("%s: attaching secondary DAC\n", sc->sc_dev.dv_xname);
789 sc->sc_ei[EAP_I2].ei_audiodev =
790 audio_attach_mi(eap_hw_if, &sc->sc_ei[EAP_I2], &sc->sc_dev);
791 #endif
792
793 #if NMIDI > 0
794 sc->sc_mididev = midi_attach_mi(&eap_midi_hw_if, sc, &sc->sc_dev);
795 #endif
796
797 #if NJOY_EAP > 0
798 if (sc->sc_1371) {
799 gpargs.gpa_iot = sc->iot;
800 gpargs.gpa_ioh = sc->ioh;
801 sc->sc_gameport = eap_joy_attach(&sc->sc_dev, &gpargs);
802 }
803 #endif
804 }
805
806 int
807 eap_detach(struct device *self, int flags)
808 {
809 struct eap_softc *sc = (struct eap_softc *) self;
810 int res;
811 #if NJOY_EAP > 0
812 struct eap_gameport_args gpargs;
813
814 if (sc->sc_gameport) {
815 gpargs.gpa_iot = sc->iot;
816 gpargs.gpa_ioh = sc->ioh;
817 res = eap_joy_detach(sc->sc_gameport, &gpargs);
818 if (res)
819 return (res);
820 }
821 #endif
822 #if NMIDI > 0
823 if (sc->sc_mididev != NULL) {
824 res = config_detach(sc->sc_mididev, 0);
825 if (res)
826 return (res);
827 }
828 #endif
829 #ifdef EAP_USE_BOTH_DACS
830 if (sc->sc_ei[EAP_I2].ei_audiodev != NULL) {
831 res = config_detach(sc->sc_ei[EAP_I2].ei_audiodev, 0);
832 if (res)
833 return (res);
834 }
835 #endif
836 if (sc->sc_ei[EAP_I1].ei_audiodev != NULL) {
837 res = config_detach(sc->sc_ei[EAP_I1].ei_audiodev, 0);
838 if (res)
839 return (res);
840 }
841
842 bus_space_unmap(sc->iot, sc->ioh, sc->iosz);
843 pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
844
845 return (0);
846 }
847
848 int
849 eap1371_attach_codec(void *sc_, struct ac97_codec_if *codec_if)
850 {
851 struct eap_softc *sc = sc_;
852
853 sc->codec_if = codec_if;
854 return (0);
855 }
856
857 int
858 eap1371_reset_codec(void *sc_)
859 {
860 struct eap_softc *sc = sc_;
861 u_int32_t icsc;
862 int s;
863
864 s = splaudio();
865 icsc = EREAD4(sc, EAP_ICSC);
866 EWRITE4(sc, EAP_ICSC, icsc | E1371_SYNC_RES);
867 delay(20);
868 EWRITE4(sc, EAP_ICSC, icsc & ~E1371_SYNC_RES);
869 delay(1);
870 splx(s);
871
872 return 0;
873 }
874
875 int
876 eap_intr(void *p)
877 {
878 struct eap_softc *sc = p;
879 u_int32_t intr, sic;
880
881 intr = EREAD4(sc, EAP_ICSS);
882 if (!(intr & EAP_INTR))
883 return (0);
884 sic = EREAD4(sc, EAP_SIC);
885 DPRINTFN(5, ("eap_intr: ICSS=0x%08x, SIC=0x%08x\n", intr, sic));
886 if (intr & EAP_I_ADC) {
887 #if 0
888 /*
889 * XXX This is a hack!
890 * The EAP chip sometimes generates the recording interrupt
891 * while it is still transferring the data. To make sure
892 * it has all arrived we busy wait until the count is right.
893 * The transfer we are waiting for is 8 longwords.
894 */
895 int s, nw, n;
896 EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
897 s = EREAD4(sc, EAP_ADC_CSR);
898 nw = ((s & 0xffff) + 1) >> 2; /* # of words in DMA */
899 n = 0;
900 while (((EREAD4(sc, EAP_ADC_SIZE) >> 16) + 8) % nw == 0) {
901 delay(10);
902 if (++n > 100) {
903 printf("eapintr: DMA fix timeout");
904 break;
905 }
906 }
907 /* Continue with normal interrupt handling. */
908 #endif
909 EWRITE4(sc, EAP_SIC, sic & ~EAP_R1_INTR_EN);
910 EWRITE4(sc, EAP_SIC, sic | EAP_R1_INTR_EN);
911 if (sc->sc_rintr)
912 sc->sc_rintr(sc->sc_rarg);
913 }
914
915 if (intr & EAP_I_DAC2) {
916 EWRITE4(sc, EAP_SIC, sic & ~EAP_P2_INTR_EN);
917 EWRITE4(sc, EAP_SIC, sic | EAP_P2_INTR_EN);
918 if (sc->sc_ei[EAP_DAC2].ei_pintr)
919 sc->sc_ei[EAP_DAC2].ei_pintr(sc->sc_ei[EAP_DAC2].ei_parg);
920 }
921
922 if (intr & EAP_I_DAC1) {
923 EWRITE4(sc, EAP_SIC, sic & ~EAP_P1_INTR_EN);
924 EWRITE4(sc, EAP_SIC, sic | EAP_P1_INTR_EN);
925 if (sc->sc_ei[EAP_DAC1].ei_pintr)
926 sc->sc_ei[EAP_DAC1].ei_pintr(sc->sc_ei[EAP_DAC1].ei_parg);
927 }
928
929 if (intr & EAP_I_MCCB)
930 panic("eap_intr: unexpected MCCB interrupt");
931 #if NMIDI > 0
932 if ((intr & EAP_I_UART) && sc->sc_iintr != NULL) {
933 u_int32_t data;
934
935 if (EREAD1(sc, EAP_UART_STATUS) & EAP_US_RXINT) {
936 while (EREAD1(sc, EAP_UART_STATUS) & EAP_US_RXRDY) {
937 data = EREAD1(sc, EAP_UART_DATA);
938 sc->sc_iintr(sc->sc_arg, data);
939 }
940 }
941 }
942 #endif
943 return (1);
944 }
945
946 int
947 eap_allocmem(struct eap_softc *sc, size_t size, size_t align, struct eap_dma *p)
948 {
949 int error;
950
951 p->size = size;
952 error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
953 p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
954 &p->nsegs, BUS_DMA_NOWAIT);
955 if (error)
956 return (error);
957
958 error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
959 &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
960 if (error)
961 goto free;
962
963 error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
964 0, BUS_DMA_NOWAIT, &p->map);
965 if (error)
966 goto unmap;
967
968 error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
969 BUS_DMA_NOWAIT);
970 if (error)
971 goto destroy;
972 return (0);
973
974 destroy:
975 bus_dmamap_destroy(sc->sc_dmatag, p->map);
976 unmap:
977 bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
978 free:
979 bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
980 return (error);
981 }
982
983 int
984 eap_freemem(struct eap_softc *sc, struct eap_dma *p)
985 {
986 bus_dmamap_unload(sc->sc_dmatag, p->map);
987 bus_dmamap_destroy(sc->sc_dmatag, p->map);
988 bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
989 bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
990 return (0);
991 }
992
993 int
994 eap_open(void *addr, int flags)
995 {
996 struct eap_instance *ei = addr;
997
998 /* there is only one ADC */
999 if (ei->index == EAP_I2 && flags & FREAD)
1000 return (EOPNOTSUPP);
1001
1002 return (0);
1003 }
1004
1005 int
1006 eap_query_encoding(void *addr, struct audio_encoding *fp)
1007 {
1008 switch (fp->index) {
1009 case 0:
1010 strcpy(fp->name, AudioEulinear);
1011 fp->encoding = AUDIO_ENCODING_ULINEAR;
1012 fp->precision = 8;
1013 fp->flags = 0;
1014 return (0);
1015 case 1:
1016 strcpy(fp->name, AudioEmulaw);
1017 fp->encoding = AUDIO_ENCODING_ULAW;
1018 fp->precision = 8;
1019 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1020 return (0);
1021 case 2:
1022 strcpy(fp->name, AudioEalaw);
1023 fp->encoding = AUDIO_ENCODING_ALAW;
1024 fp->precision = 8;
1025 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1026 return (0);
1027 case 3:
1028 strcpy(fp->name, AudioEslinear);
1029 fp->encoding = AUDIO_ENCODING_SLINEAR;
1030 fp->precision = 8;
1031 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1032 return (0);
1033 case 4:
1034 strcpy(fp->name, AudioEslinear_le);
1035 fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
1036 fp->precision = 16;
1037 fp->flags = 0;
1038 return (0);
1039 case 5:
1040 strcpy(fp->name, AudioEulinear_le);
1041 fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
1042 fp->precision = 16;
1043 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1044 return (0);
1045 case 6:
1046 strcpy(fp->name, AudioEslinear_be);
1047 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
1048 fp->precision = 16;
1049 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1050 return (0);
1051 case 7:
1052 strcpy(fp->name, AudioEulinear_be);
1053 fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
1054 fp->precision = 16;
1055 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1056 return (0);
1057 default:
1058 return (EINVAL);
1059 }
1060 }
1061
1062 int
1063 eap_set_params(void *addr, int setmode, int usemode,
1064 audio_params_t *play, audio_params_t *rec,
1065 stream_filter_list_t *pfil, stream_filter_list_t *rfil)
1066 {
1067 struct eap_instance *ei = addr;
1068 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1069 struct audio_params *p;
1070 stream_filter_list_t *fil;
1071 int mode, i;
1072 u_int32_t div;
1073
1074 /*
1075 * The es1370 only has one clock, so make the sample rates match.
1076 * This only applies for ADC/DAC2. The FM DAC is handled below.
1077 */
1078 if (!sc->sc_1371 && ei->index == EAP_DAC2) {
1079 if (play->sample_rate != rec->sample_rate &&
1080 usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
1081 if (setmode == AUMODE_PLAY) {
1082 rec->sample_rate = play->sample_rate;
1083 setmode |= AUMODE_RECORD;
1084 } else if (setmode == AUMODE_RECORD) {
1085 play->sample_rate = rec->sample_rate;
1086 setmode |= AUMODE_PLAY;
1087 } else
1088 return (EINVAL);
1089 }
1090 }
1091
1092 for (mode = AUMODE_RECORD; mode != -1;
1093 mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
1094 if ((setmode & mode) == 0)
1095 continue;
1096
1097 p = mode == AUMODE_PLAY ? play : rec;
1098
1099 if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
1100 (p->precision != 8 && p->precision != 16) ||
1101 (p->channels != 1 && p->channels != 2))
1102 return (EINVAL);
1103
1104 fil = mode == AUMODE_PLAY ? pfil : rfil;
1105 i = auconv_set_converter(eap_formats, EAP_NFORMATS,
1106 mode, p, FALSE, fil);
1107 if (i < 0)
1108 return EINVAL;
1109 }
1110
1111 if (sc->sc_1371) {
1112 eap1371_set_dac_rate(ei, play->sample_rate);
1113 eap1371_set_adc_rate(sc, rec->sample_rate);
1114 } else if (ei->index == EAP_DAC2) {
1115 /* Set the speed */
1116 DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n",
1117 EREAD4(sc, EAP_ICSC)));
1118 div = EREAD4(sc, EAP_ICSC) & ~EAP_PCLKBITS;
1119 /*
1120 * XXX
1121 * The -2 isn't documented, but seemed to make the wall
1122 * time match
1123 * what I expect. - mycroft
1124 */
1125 if (usemode == AUMODE_RECORD)
1126 div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ /
1127 rec->sample_rate - 2);
1128 else
1129 div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ /
1130 play->sample_rate - 2);
1131 #if 0
1132 div |= EAP_CCB_INTRM;
1133 #else
1134 /*
1135 * It is not obvious how to acknowledge MCCB interrupts, so
1136 * we had better not enable them.
1137 */
1138 #endif
1139 EWRITE4(sc, EAP_ICSC, div);
1140 DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div));
1141 } else {
1142 /*
1143 * The FM DAC has only a few fixed-frequency choises, so
1144 * pick out the best candidate.
1145 */
1146 div = EREAD4(sc, EAP_ICSC);
1147 DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n", div));
1148
1149 div &= ~EAP_WTSRSEL;
1150 if (play->sample_rate < 8268)
1151 div |= EAP_WTSRSEL_5;
1152 else if (play->sample_rate < 16537)
1153 div |= EAP_WTSRSEL_11;
1154 else if (play->sample_rate < 33075)
1155 div |= EAP_WTSRSEL_22;
1156 else
1157 div |= EAP_WTSRSEL_44;
1158
1159 EWRITE4(sc, EAP_ICSC, div);
1160 DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div));
1161 }
1162
1163 return (0);
1164 }
1165
1166 int
1167 eap_round_blocksize(void *addr, int blk, int mode, const audio_params_t *param)
1168 {
1169 return (blk & -32); /* keep good alignment */
1170 }
1171
1172 int
1173 eap_trigger_output(
1174 void *addr,
1175 void *start,
1176 void *end,
1177 int blksize,
1178 void (*intr)(void *),
1179 void *arg,
1180 const audio_params_t *param)
1181 {
1182 struct eap_instance *ei = addr;
1183 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1184 struct eap_dma *p;
1185 u_int32_t icsc, sic;
1186 int sampshift;
1187
1188 #ifdef DIAGNOSTIC
1189 if (ei->ei_prun)
1190 panic("eap_trigger_output: already running");
1191 ei->ei_prun = 1;
1192 #endif
1193
1194 DPRINTFN(1, ("eap_trigger_output: sc=%p start=%p end=%p "
1195 "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
1196 ei->ei_pintr = intr;
1197 ei->ei_parg = arg;
1198
1199 sic = EREAD4(sc, EAP_SIC);
1200 sic &= ~(EAP_S_EB(ei->index) | EAP_S_MB(ei->index) | EAP_INC_BITS);
1201
1202 if (ei->index == EAP_DAC2)
1203 sic |= EAP_SET_P2_ST_INC(0)
1204 | EAP_SET_P2_END_INC(param->precision / 8);
1205
1206 sampshift = 0;
1207 if (param->precision == 16) {
1208 sic |= EAP_S_EB(ei->index);
1209 sampshift++;
1210 }
1211 if (param->channels == 2) {
1212 sic |= EAP_S_MB(ei->index);
1213 sampshift++;
1214 }
1215 EWRITE4(sc, EAP_SIC, sic & ~EAP_P_INTR_EN(ei->index));
1216 EWRITE4(sc, EAP_SIC, sic | EAP_P_INTR_EN(ei->index));
1217
1218 for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
1219 ;
1220 if (!p) {
1221 printf("eap_trigger_output: bad addr %p\n", start);
1222 return (EINVAL);
1223 }
1224
1225 if (ei->index == EAP_DAC2) {
1226 DPRINTF(("eap_trigger_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
1227 (int)DMAADDR(p),
1228 (int)EAP_SET_SIZE(0,
1229 (((char *)end - (char *)start) >> 2) - 1)));
1230 EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
1231 EWRITE4(sc, EAP_DAC2_ADDR, DMAADDR(p));
1232 EWRITE4(sc, EAP_DAC2_SIZE,
1233 EAP_SET_SIZE(0,
1234 ((char *)end - (char *)start) >> 2) - 1);
1235 EWRITE4(sc, EAP_DAC2_CSR, (blksize >> sampshift) - 1);
1236 } else if (ei->index == EAP_DAC1) {
1237 DPRINTF(("eap_trigger_output: DAC1_ADDR=0x%x, DAC1_SIZE=0x%x\n",
1238 (int)DMAADDR(p),
1239 (int)EAP_SET_SIZE(0,
1240 (((char *)end - (char *)start) >> 2) - 1)));
1241 EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
1242 EWRITE4(sc, EAP_DAC1_ADDR, DMAADDR(p));
1243 EWRITE4(sc, EAP_DAC1_SIZE,
1244 EAP_SET_SIZE(0,
1245 ((char *)end - (char *)start) >> 2) - 1);
1246 EWRITE4(sc, EAP_DAC1_CSR, (blksize >> sampshift) - 1);
1247 }
1248 #ifdef DIAGNOSTIC
1249 else
1250 panic("eap_trigger_output: impossible instance %d", ei->index);
1251 #endif
1252
1253 if (sc->sc_1371)
1254 EWRITE4(sc, E1371_SRC, 0);
1255
1256 icsc = EREAD4(sc, EAP_ICSC);
1257 icsc |= EAP_DAC_EN(ei->index);
1258 EWRITE4(sc, EAP_ICSC, icsc);
1259
1260 DPRINTFN(1, ("eap_trigger_output: set ICSC = 0x%08x\n", icsc));
1261
1262 return (0);
1263 }
1264
1265 int
1266 eap_trigger_input(
1267 void *addr,
1268 void *start,
1269 void *end,
1270 int blksize,
1271 void (*intr)(void *),
1272 void *arg,
1273 const audio_params_t *param)
1274 {
1275 struct eap_instance *ei = addr;
1276 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1277 struct eap_dma *p;
1278 u_int32_t icsc, sic;
1279 int sampshift;
1280
1281 #ifdef DIAGNOSTIC
1282 if (sc->sc_rrun)
1283 panic("eap_trigger_input: already running");
1284 sc->sc_rrun = 1;
1285 #endif
1286
1287 DPRINTFN(1, ("eap_trigger_input: ei=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
1288 addr, start, end, blksize, intr, arg));
1289 sc->sc_rintr = intr;
1290 sc->sc_rarg = arg;
1291
1292 sic = EREAD4(sc, EAP_SIC);
1293 sic &= ~(EAP_R1_S_EB | EAP_R1_S_MB);
1294 sampshift = 0;
1295 if (param->precision == 16) {
1296 sic |= EAP_R1_S_EB;
1297 sampshift++;
1298 }
1299 if (param->channels == 2) {
1300 sic |= EAP_R1_S_MB;
1301 sampshift++;
1302 }
1303 EWRITE4(sc, EAP_SIC, sic & ~EAP_R1_INTR_EN);
1304 EWRITE4(sc, EAP_SIC, sic | EAP_R1_INTR_EN);
1305
1306 for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
1307 ;
1308 if (!p) {
1309 printf("eap_trigger_input: bad addr %p\n", start);
1310 return (EINVAL);
1311 }
1312
1313 DPRINTF(("eap_trigger_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
1314 (int)DMAADDR(p),
1315 (int)EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1)));
1316 EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
1317 EWRITE4(sc, EAP_ADC_ADDR, DMAADDR(p));
1318 EWRITE4(sc, EAP_ADC_SIZE,
1319 EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1));
1320
1321 EWRITE4(sc, EAP_ADC_CSR, (blksize >> sampshift) - 1);
1322
1323 if (sc->sc_1371)
1324 EWRITE4(sc, E1371_SRC, 0);
1325
1326 icsc = EREAD4(sc, EAP_ICSC);
1327 icsc |= EAP_ADC_EN;
1328 EWRITE4(sc, EAP_ICSC, icsc);
1329
1330 DPRINTFN(1, ("eap_trigger_input: set ICSC = 0x%08x\n", icsc));
1331
1332 return (0);
1333 }
1334
1335 int
1336 eap_halt_output(void *addr)
1337 {
1338 struct eap_instance *ei = addr;
1339 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1340 u_int32_t icsc;
1341
1342 DPRINTF(("eap: eap_halt_output\n"));
1343 icsc = EREAD4(sc, EAP_ICSC);
1344 EWRITE4(sc, EAP_ICSC, icsc & ~(EAP_DAC_EN(ei->index)));
1345 ei->ei_pintr = 0;
1346 #ifdef DIAGNOSTIC
1347 ei->ei_prun = 0;
1348 #endif
1349
1350 return (0);
1351 }
1352
1353 int
1354 eap_halt_input(void *addr)
1355 {
1356 struct eap_instance *ei = addr;
1357 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1358 u_int32_t icsc;
1359
1360 #define EAP_USE_FMDAC_ALSO
1361 DPRINTF(("eap: eap_halt_input\n"));
1362 icsc = EREAD4(sc, EAP_ICSC);
1363 EWRITE4(sc, EAP_ICSC, icsc & ~EAP_ADC_EN);
1364 sc->sc_rintr = 0;
1365 #ifdef DIAGNOSTIC
1366 sc->sc_rrun = 0;
1367 #endif
1368
1369 return (0);
1370 }
1371
1372 int
1373 eap_getdev(void *addr, struct audio_device *retp)
1374 {
1375 *retp = eap_device;
1376 return (0);
1377 }
1378
1379 int
1380 eap1371_mixer_set_port(void *addr, mixer_ctrl_t *cp)
1381 {
1382 struct eap_instance *ei = addr;
1383 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1384
1385 return (sc->codec_if->vtbl->mixer_set_port(sc->codec_if, cp));
1386 }
1387
1388 int
1389 eap1371_mixer_get_port(void *addr, mixer_ctrl_t *cp)
1390 {
1391 struct eap_instance *ei = addr;
1392 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1393
1394 return (sc->codec_if->vtbl->mixer_get_port(sc->codec_if, cp));
1395 }
1396
1397 int
1398 eap1371_query_devinfo(void *addr, mixer_devinfo_t *dip)
1399 {
1400 struct eap_instance *ei = addr;
1401 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1402
1403 return (sc->codec_if->vtbl->query_devinfo(sc->codec_if, dip));
1404 }
1405
1406 int
1407 eap1371_get_portnum_by_name(struct eap_softc *sc,
1408 char *class, char *device, char *qualifier)
1409 {
1410 return (sc->codec_if->vtbl->get_portnum_by_name(sc->codec_if, class,
1411 device, qualifier));
1412 }
1413
1414 void
1415 eap1370_set_mixer(struct eap_softc *sc, int a, int d)
1416 {
1417 eap1370_write_codec(sc, a, d);
1418
1419 sc->sc_port[a] = d;
1420 DPRINTFN(1, ("eap1370_mixer_set_port port 0x%02x = 0x%02x\n", a, d));
1421 }
1422
1423 int
1424 eap1370_mixer_set_port(void *addr, mixer_ctrl_t *cp)
1425 {
1426 struct eap_instance *ei = addr;
1427 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1428 int lval, rval, l, r, la, ra;
1429 int l1, r1, l2, r2, m, o1, o2;
1430
1431 if (cp->dev == EAP_RECORD_SOURCE) {
1432 if (cp->type != AUDIO_MIXER_SET)
1433 return (EINVAL);
1434 m = sc->sc_record_source = cp->un.mask;
1435 l1 = l2 = r1 = r2 = 0;
1436 if (m & (1 << EAP_VOICE_VOL))
1437 l2 |= AK_M_VOICE, r2 |= AK_M_VOICE;
1438 if (m & (1 << EAP_FM_VOL))
1439 l1 |= AK_M_FM_L, r1 |= AK_M_FM_R;
1440 if (m & (1 << EAP_CD_VOL))
1441 l1 |= AK_M_CD_L, r1 |= AK_M_CD_R;
1442 if (m & (1 << EAP_LINE_VOL))
1443 l1 |= AK_M_LINE_L, r1 |= AK_M_LINE_R;
1444 if (m & (1 << EAP_AUX_VOL))
1445 l2 |= AK_M2_AUX_L, r2 |= AK_M2_AUX_R;
1446 if (m & (1 << EAP_MIC_VOL))
1447 l2 |= AK_M_TMIC, r2 |= AK_M_TMIC;
1448 eap1370_set_mixer(sc, AK_IN_MIXER1_L, l1);
1449 eap1370_set_mixer(sc, AK_IN_MIXER1_R, r1);
1450 eap1370_set_mixer(sc, AK_IN_MIXER2_L, l2);
1451 eap1370_set_mixer(sc, AK_IN_MIXER2_R, r2);
1452 return (0);
1453 }
1454 if (cp->dev == EAP_OUTPUT_SELECT) {
1455 if (cp->type != AUDIO_MIXER_SET)
1456 return (EINVAL);
1457 m = sc->sc_output_source = cp->un.mask;
1458 o1 = o2 = 0;
1459 if (m & (1 << EAP_VOICE_VOL))
1460 o2 |= AK_M_VOICE_L | AK_M_VOICE_R;
1461 if (m & (1 << EAP_FM_VOL))
1462 o1 |= AK_M_FM_L | AK_M_FM_R;
1463 if (m & (1 << EAP_CD_VOL))
1464 o1 |= AK_M_CD_L | AK_M_CD_R;
1465 if (m & (1 << EAP_LINE_VOL))
1466 o1 |= AK_M_LINE_L | AK_M_LINE_R;
1467 if (m & (1 << EAP_AUX_VOL))
1468 o2 |= AK_M_AUX_L | AK_M_AUX_R;
1469 if (m & (1 << EAP_MIC_VOL))
1470 o1 |= AK_M_MIC;
1471 eap1370_set_mixer(sc, AK_OUT_MIXER1, o1);
1472 eap1370_set_mixer(sc, AK_OUT_MIXER2, o2);
1473 return (0);
1474 }
1475 if (cp->dev == EAP_MIC_PREAMP) {
1476 if (cp->type != AUDIO_MIXER_ENUM)
1477 return (EINVAL);
1478 if (cp->un.ord != 0 && cp->un.ord != 1)
1479 return (EINVAL);
1480 sc->sc_mic_preamp = cp->un.ord;
1481 eap1370_set_mixer(sc, AK_MGAIN, cp->un.ord);
1482 return (0);
1483 }
1484 if (cp->type != AUDIO_MIXER_VALUE)
1485 return (EINVAL);
1486 if (cp->un.value.num_channels == 1)
1487 lval = rval = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
1488 else if (cp->un.value.num_channels == 2) {
1489 lval = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
1490 rval = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
1491 } else
1492 return (EINVAL);
1493 ra = -1;
1494 switch (cp->dev) {
1495 case EAP_MASTER_VOL:
1496 l = VOL_TO_ATT5(lval);
1497 r = VOL_TO_ATT5(rval);
1498 la = AK_MASTER_L;
1499 ra = AK_MASTER_R;
1500 break;
1501 case EAP_MIC_VOL:
1502 if (cp->un.value.num_channels != 1)
1503 return (EINVAL);
1504 la = AK_MIC;
1505 goto lr;
1506 case EAP_VOICE_VOL:
1507 la = AK_VOICE_L;
1508 ra = AK_VOICE_R;
1509 goto lr;
1510 case EAP_FM_VOL:
1511 la = AK_FM_L;
1512 ra = AK_FM_R;
1513 goto lr;
1514 case EAP_CD_VOL:
1515 la = AK_CD_L;
1516 ra = AK_CD_R;
1517 goto lr;
1518 case EAP_LINE_VOL:
1519 la = AK_LINE_L;
1520 ra = AK_LINE_R;
1521 goto lr;
1522 case EAP_AUX_VOL:
1523 la = AK_AUX_L;
1524 ra = AK_AUX_R;
1525 lr:
1526 l = VOL_TO_GAIN5(lval);
1527 r = VOL_TO_GAIN5(rval);
1528 break;
1529 default:
1530 return (EINVAL);
1531 }
1532 eap1370_set_mixer(sc, la, l);
1533 if (ra >= 0) {
1534 eap1370_set_mixer(sc, ra, r);
1535 }
1536 return (0);
1537 }
1538
1539 int
1540 eap1370_mixer_get_port(void *addr, mixer_ctrl_t *cp)
1541 {
1542 struct eap_instance *ei = addr;
1543 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1544 int la, ra, l, r;
1545
1546 switch (cp->dev) {
1547 case EAP_RECORD_SOURCE:
1548 if (cp->type != AUDIO_MIXER_SET)
1549 return (EINVAL);
1550 cp->un.mask = sc->sc_record_source;
1551 return (0);
1552 case EAP_OUTPUT_SELECT:
1553 if (cp->type != AUDIO_MIXER_SET)
1554 return (EINVAL);
1555 cp->un.mask = sc->sc_output_source;
1556 return (0);
1557 case EAP_MIC_PREAMP:
1558 if (cp->type != AUDIO_MIXER_ENUM)
1559 return (EINVAL);
1560 cp->un.ord = sc->sc_mic_preamp;
1561 return (0);
1562 case EAP_MASTER_VOL:
1563 l = ATT5_TO_VOL(sc->sc_port[AK_MASTER_L]);
1564 r = ATT5_TO_VOL(sc->sc_port[AK_MASTER_R]);
1565 break;
1566 case EAP_MIC_VOL:
1567 if (cp->un.value.num_channels != 1)
1568 return (EINVAL);
1569 la = ra = AK_MIC;
1570 goto lr;
1571 case EAP_VOICE_VOL:
1572 la = AK_VOICE_L;
1573 ra = AK_VOICE_R;
1574 goto lr;
1575 case EAP_FM_VOL:
1576 la = AK_FM_L;
1577 ra = AK_FM_R;
1578 goto lr;
1579 case EAP_CD_VOL:
1580 la = AK_CD_L;
1581 ra = AK_CD_R;
1582 goto lr;
1583 case EAP_LINE_VOL:
1584 la = AK_LINE_L;
1585 ra = AK_LINE_R;
1586 goto lr;
1587 case EAP_AUX_VOL:
1588 la = AK_AUX_L;
1589 ra = AK_AUX_R;
1590 lr:
1591 l = GAIN5_TO_VOL(sc->sc_port[la]);
1592 r = GAIN5_TO_VOL(sc->sc_port[ra]);
1593 break;
1594 default:
1595 return (EINVAL);
1596 }
1597 if (cp->un.value.num_channels == 1)
1598 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
1599 else if (cp->un.value.num_channels == 2) {
1600 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
1601 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
1602 } else
1603 return (EINVAL);
1604 return (0);
1605 }
1606
1607 int
1608 eap1370_query_devinfo(void *addr, mixer_devinfo_t *dip)
1609 {
1610
1611 switch (dip->index) {
1612 case EAP_MASTER_VOL:
1613 dip->type = AUDIO_MIXER_VALUE;
1614 dip->mixer_class = EAP_OUTPUT_CLASS;
1615 dip->prev = dip->next = AUDIO_MIXER_LAST;
1616 strcpy(dip->label.name, AudioNmaster);
1617 dip->un.v.num_channels = 2;
1618 strcpy(dip->un.v.units.name, AudioNvolume);
1619 return (0);
1620 case EAP_VOICE_VOL:
1621 dip->type = AUDIO_MIXER_VALUE;
1622 dip->mixer_class = EAP_INPUT_CLASS;
1623 dip->prev = AUDIO_MIXER_LAST;
1624 dip->next = AUDIO_MIXER_LAST;
1625 strcpy(dip->label.name, AudioNdac);
1626 dip->un.v.num_channels = 2;
1627 strcpy(dip->un.v.units.name, AudioNvolume);
1628 return (0);
1629 case EAP_FM_VOL:
1630 dip->type = AUDIO_MIXER_VALUE;
1631 dip->mixer_class = EAP_INPUT_CLASS;
1632 dip->prev = AUDIO_MIXER_LAST;
1633 dip->next = AUDIO_MIXER_LAST;
1634 strcpy(dip->label.name, AudioNfmsynth);
1635 dip->un.v.num_channels = 2;
1636 strcpy(dip->un.v.units.name, AudioNvolume);
1637 return (0);
1638 case EAP_CD_VOL:
1639 dip->type = AUDIO_MIXER_VALUE;
1640 dip->mixer_class = EAP_INPUT_CLASS;
1641 dip->prev = AUDIO_MIXER_LAST;
1642 dip->next = AUDIO_MIXER_LAST;
1643 strcpy(dip->label.name, AudioNcd);
1644 dip->un.v.num_channels = 2;
1645 strcpy(dip->un.v.units.name, AudioNvolume);
1646 return (0);
1647 case EAP_LINE_VOL:
1648 dip->type = AUDIO_MIXER_VALUE;
1649 dip->mixer_class = EAP_INPUT_CLASS;
1650 dip->prev = AUDIO_MIXER_LAST;
1651 dip->next = AUDIO_MIXER_LAST;
1652 strcpy(dip->label.name, AudioNline);
1653 dip->un.v.num_channels = 2;
1654 strcpy(dip->un.v.units.name, AudioNvolume);
1655 return (0);
1656 case EAP_AUX_VOL:
1657 dip->type = AUDIO_MIXER_VALUE;
1658 dip->mixer_class = EAP_INPUT_CLASS;
1659 dip->prev = AUDIO_MIXER_LAST;
1660 dip->next = AUDIO_MIXER_LAST;
1661 strcpy(dip->label.name, AudioNaux);
1662 dip->un.v.num_channels = 2;
1663 strcpy(dip->un.v.units.name, AudioNvolume);
1664 return (0);
1665 case EAP_MIC_VOL:
1666 dip->type = AUDIO_MIXER_VALUE;
1667 dip->mixer_class = EAP_INPUT_CLASS;
1668 dip->prev = AUDIO_MIXER_LAST;
1669 dip->next = EAP_MIC_PREAMP;
1670 strcpy(dip->label.name, AudioNmicrophone);
1671 dip->un.v.num_channels = 1;
1672 strcpy(dip->un.v.units.name, AudioNvolume);
1673 return (0);
1674 case EAP_RECORD_SOURCE:
1675 dip->mixer_class = EAP_RECORD_CLASS;
1676 dip->prev = dip->next = AUDIO_MIXER_LAST;
1677 strcpy(dip->label.name, AudioNsource);
1678 dip->type = AUDIO_MIXER_SET;
1679 dip->un.s.num_mem = 6;
1680 strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1681 dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1682 strcpy(dip->un.s.member[1].label.name, AudioNcd);
1683 dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1684 strcpy(dip->un.s.member[2].label.name, AudioNline);
1685 dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1686 strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1687 dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1688 strcpy(dip->un.s.member[4].label.name, AudioNaux);
1689 dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1690 strcpy(dip->un.s.member[5].label.name, AudioNdac);
1691 dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1692 return (0);
1693 case EAP_OUTPUT_SELECT:
1694 dip->mixer_class = EAP_OUTPUT_CLASS;
1695 dip->prev = dip->next = AUDIO_MIXER_LAST;
1696 strcpy(dip->label.name, AudioNselect);
1697 dip->type = AUDIO_MIXER_SET;
1698 dip->un.s.num_mem = 6;
1699 strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1700 dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1701 strcpy(dip->un.s.member[1].label.name, AudioNcd);
1702 dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1703 strcpy(dip->un.s.member[2].label.name, AudioNline);
1704 dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1705 strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1706 dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1707 strcpy(dip->un.s.member[4].label.name, AudioNaux);
1708 dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1709 strcpy(dip->un.s.member[5].label.name, AudioNdac);
1710 dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1711 return (0);
1712 case EAP_MIC_PREAMP:
1713 dip->type = AUDIO_MIXER_ENUM;
1714 dip->mixer_class = EAP_INPUT_CLASS;
1715 dip->prev = EAP_MIC_VOL;
1716 dip->next = AUDIO_MIXER_LAST;
1717 strcpy(dip->label.name, AudioNpreamp);
1718 dip->un.e.num_mem = 2;
1719 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1720 dip->un.e.member[0].ord = 0;
1721 strcpy(dip->un.e.member[1].label.name, AudioNon);
1722 dip->un.e.member[1].ord = 1;
1723 return (0);
1724 case EAP_OUTPUT_CLASS:
1725 dip->type = AUDIO_MIXER_CLASS;
1726 dip->mixer_class = EAP_OUTPUT_CLASS;
1727 dip->next = dip->prev = AUDIO_MIXER_LAST;
1728 strcpy(dip->label.name, AudioCoutputs);
1729 return (0);
1730 case EAP_RECORD_CLASS:
1731 dip->type = AUDIO_MIXER_CLASS;
1732 dip->mixer_class = EAP_RECORD_CLASS;
1733 dip->next = dip->prev = AUDIO_MIXER_LAST;
1734 strcpy(dip->label.name, AudioCrecord);
1735 return (0);
1736 case EAP_INPUT_CLASS:
1737 dip->type = AUDIO_MIXER_CLASS;
1738 dip->mixer_class = EAP_INPUT_CLASS;
1739 dip->next = dip->prev = AUDIO_MIXER_LAST;
1740 strcpy(dip->label.name, AudioCinputs);
1741 return (0);
1742 }
1743 return (ENXIO);
1744 }
1745
1746 void *
1747 eap_malloc(void *addr, int direction, size_t size,
1748 struct malloc_type *pool, int flags)
1749 {
1750 struct eap_instance *ei = addr;
1751 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1752 struct eap_dma *p;
1753 int error;
1754
1755 p = malloc(sizeof(*p), pool, flags);
1756 if (!p)
1757 return (0);
1758 error = eap_allocmem(sc, size, 16, p);
1759 if (error) {
1760 free(p, pool);
1761 return (0);
1762 }
1763 p->next = sc->sc_dmas;
1764 sc->sc_dmas = p;
1765 return (KERNADDR(p));
1766 }
1767
1768 void
1769 eap_free(void *addr, void *ptr, struct malloc_type *pool)
1770 {
1771 struct eap_instance *ei = addr;
1772 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1773 struct eap_dma **pp, *p;
1774
1775 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) {
1776 if (KERNADDR(p) == ptr) {
1777 eap_freemem(sc, p);
1778 *pp = p->next;
1779 free(p, pool);
1780 return;
1781 }
1782 }
1783 }
1784
1785 size_t
1786 eap_round_buffersize(void *addr, int direction, size_t size)
1787 {
1788
1789 return (size);
1790 }
1791
1792 paddr_t
1793 eap_mappage(void *addr, void *mem, off_t off, int prot)
1794 {
1795 struct eap_instance *ei = addr;
1796 struct eap_softc *sc = (struct eap_softc *)ei->parent;
1797 struct eap_dma *p;
1798
1799 if (off < 0)
1800 return (-1);
1801 for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
1802 ;
1803 if (!p)
1804 return (-1);
1805 return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
1806 off, prot, BUS_DMA_WAITOK));
1807 }
1808
1809 int
1810 eap_get_props(void *addr)
1811 {
1812
1813 return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT |
1814 AUDIO_PROP_FULLDUPLEX);
1815 }
1816
1817 #if NMIDI > 0
1818 int
1819 eap_midi_open(void *addr, int flags,
1820 void (*iintr)(void *, int),
1821 void (*ointr)(void *),
1822 void *arg)
1823 {
1824 struct eap_softc *sc = addr;
1825 u_int32_t uctrl;
1826
1827 sc->sc_iintr = iintr;
1828 sc->sc_ointr = ointr;
1829 sc->sc_arg = arg;
1830
1831 EWRITE4(sc, EAP_ICSC, EREAD4(sc, EAP_ICSC) | EAP_UART_EN);
1832 uctrl = 0;
1833 if (flags & FREAD)
1834 uctrl |= EAP_UC_RXINTEN;
1835 #if 0
1836 /* I don't understand ../midi.c well enough to use output interrupts */
1837 if (flags & FWRITE)
1838 uctrl |= EAP_UC_TXINTEN; */
1839 #endif
1840 EWRITE1(sc, EAP_UART_CONTROL, uctrl);
1841
1842 return (0);
1843 }
1844
1845 void
1846 eap_midi_close(void *addr)
1847 {
1848 struct eap_softc *sc = addr;
1849
1850 tsleep(sc, PWAIT, "eapclm", hz/10); /* give uart a chance to drain */
1851 EWRITE1(sc, EAP_UART_CONTROL, 0);
1852 EWRITE4(sc, EAP_ICSC, EREAD4(sc, EAP_ICSC) & ~EAP_UART_EN);
1853
1854 sc->sc_iintr = 0;
1855 sc->sc_ointr = 0;
1856 }
1857
1858 int
1859 eap_midi_output(void *addr, int d)
1860 {
1861 struct eap_softc *sc = addr;
1862 int x;
1863
1864 for (x = 0; x != MIDI_BUSY_WAIT; x++) {
1865 if (EREAD1(sc, EAP_UART_STATUS) & EAP_US_TXRDY) {
1866 EWRITE1(sc, EAP_UART_DATA, d);
1867 return (0);
1868 }
1869 delay(MIDI_BUSY_DELAY);
1870 }
1871 return (EIO);
1872 }
1873
1874 void
1875 eap_midi_getinfo(void *addr, struct midi_info *mi)
1876 {
1877 mi->name = "AudioPCI MIDI UART";
1878 mi->props = MIDI_PROP_CAN_INPUT;
1879 }
1880
1881 #endif
1882