1 /* $NetBSD: eap.c,v 1.91 2008/03/04 22:12:55 cube Exp $ */
2 /* $OpenBSD: eap.c,v 1.6 1999/10/05 19:24:42 csapuntz Exp $ */
5 * Copyright (c) 1998, 1999, 2002 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson <augustss@NetBSD.org>, Charles M. Hannum, and
10 * Antti Kantee <pooka@NetBSD.org>.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * Debugging: Andreas Gustafsson <gson@araneus.fi>
36 * Testing: Chuck Cranor <chuck@maria.wustl.edu>
37 * Phil Nelson <phil@cs.wwu.edu>
39 * ES1371/AC97: Ezra Story <ezy@panix.com>
43 * Ensoniq ES1370 + AK4531 and ES1371/ES1373 + AC97
45 * Documentation links:
47 * ftp://ftp.alsa-project.org/pub/manuals/ensoniq/ (ES1370 and 1371 datasheets)
48 * http://web.archive.org/web/20040622012936/http://www.corbac.com/Data/Misc/es1373.ps.gz
49 * ftp://ftp.alsa-project.org/pub/manuals/asahi_kasei/4531.pdf
50 * ftp://download.intel.com/ial/scalableplatforms/audio/ac97r21.pdf
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: eap.c,v 1.91 2008/03/04 22:12:55 cube Exp $");
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/fcntl.h>
63 #include <sys/malloc.h>
64 #include <sys/device.h>
66 #include <sys/select.h>
68 #include <dev/pci/pcidevs.h>
69 #include <dev/pci/pcivar.h>
71 #include <sys/audioio.h>
72 #include <dev/audio_if.h>
73 #include <dev/midi_if.h>
74 #include <dev/audiovar.h>
75 #include <dev/mulaw.h>
76 #include <dev/auconv.h>
77 #include <dev/ic/ac97var.h>
81 #include <dev/pci/eapreg.h>
82 #include <dev/pci/eapvar.h>
88 #define DPRINTF(x) if (eapdebug) printf x
89 #define DPRINTFN(n,x) if (eapdebug>(n)) printf x
96 static int eap_match(device_t
, cfdata_t
, void *);
97 static void eap_attach(device_t
, device_t
, void *);
98 static int eap_detach(device_t
, int);
99 static int eap_intr(void *);
104 bus_dma_segment_t segs
[1];
107 struct eap_dma
*next
;
110 #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
111 #define KERNADDR(p) ((void *)((p)->addr))
114 * The card has two DACs. Using them is a bit twisted: we use DAC2
115 * as default and DAC1 as the optional secondary DAC.
119 #define EAP_I1 EAP_DAC2
120 #define EAP_I2 EAP_DAC1
121 struct eap_instance
{
125 void (*ei_pintr
)(void *); /* DMA completion intr handler */
126 void *ei_parg
; /* arg for ei_intr() */
127 device_t ei_audiodev
; /* audio device, for detach */
134 device_t sc_dev
; /* base device */
135 void *sc_ih
; /* interrupt vectoring */
137 bus_space_handle_t ioh
;
139 bus_dma_tag_t sc_dmatag
; /* DMA tag */
141 struct eap_dma
*sc_dmas
;
143 void (*sc_rintr
)(void *); /* DMA completion intr handler */
144 void *sc_rarg
; /* arg for sc_intr() */
150 void (*sc_iintr
)(void *, int); /* midi input ready handler */
151 void (*sc_ointr
)(void *); /* midi output ready handler */
156 device_t sc_gameport
;
159 u_short sc_port
[AK_NPORTS
]; /* mirror of the hardware setting */
160 u_int sc_record_source
; /* recording source mask */
161 u_int sc_input_source
; /* input source mask */
163 char sc_1371
; /* Using ES1371/AC97 codec */
165 struct ac97_codec_if
*codec_if
;
166 struct ac97_host_if host_if
;
168 struct eap_instance sc_ei
[2];
170 pci_chipset_tag_t sc_pc
; /* For detach */
173 static int eap_allocmem(struct eap_softc
*, size_t, size_t,
175 static int eap_freemem(struct eap_softc
*, struct eap_dma
*);
177 #define EWRITE1(sc, r, x) bus_space_write_1((sc)->iot, (sc)->ioh, (r), (x))
178 #define EWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
179 #define EWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
180 #define EREAD1(sc, r) bus_space_read_1((sc)->iot, (sc)->ioh, (r))
181 #define EREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
182 #define EREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
184 CFATTACH_DECL_NEW(eap
, sizeof(struct eap_softc
),
185 eap_match
, eap_attach
, eap_detach
, NULL
);
187 static int eap_open(void *, int);
188 static int eap_query_encoding(void *, struct audio_encoding
*);
189 static int eap_set_params(void *, int, int, audio_params_t
*,
190 audio_params_t
*, stream_filter_list_t
*,
191 stream_filter_list_t
*);
192 static int eap_round_blocksize(void *, int, int, const audio_params_t
*);
193 static int eap_trigger_output(void *, void *, void *, int,
194 void (*)(void *), void *,
195 const audio_params_t
*);
196 static int eap_trigger_input(void *, void *, void *, int,
197 void (*)(void *), void *,
198 const audio_params_t
*);
199 static int eap_halt_output(void *);
200 static int eap_halt_input(void *);
201 static void eap1370_write_codec(struct eap_softc
*, int, int);
202 static int eap_getdev(void *, struct audio_device
*);
203 static int eap1370_mixer_set_port(void *, mixer_ctrl_t
*);
204 static int eap1370_mixer_get_port(void *, mixer_ctrl_t
*);
205 static int eap1371_mixer_set_port(void *, mixer_ctrl_t
*);
206 static int eap1371_mixer_get_port(void *, mixer_ctrl_t
*);
207 static int eap1370_query_devinfo(void *, mixer_devinfo_t
*);
208 static void *eap_malloc(void *, int, size_t, struct malloc_type
*, int);
209 static void eap_free(void *, void *, struct malloc_type
*);
210 static size_t eap_round_buffersize(void *, int, size_t);
211 static paddr_t
eap_mappage(void *, void *, off_t
, int);
212 static int eap_get_props(void *);
213 static void eap1370_set_mixer(struct eap_softc
*, int, int);
214 static uint32_t eap1371_src_wait(struct eap_softc
*);
215 static void eap1371_set_adc_rate(struct eap_softc
*, int);
216 static void eap1371_set_dac_rate(struct eap_instance
*, int);
217 static int eap1371_src_read(struct eap_softc
*, int);
218 static void eap1371_src_write(struct eap_softc
*, int, int);
219 static int eap1371_query_devinfo(void *, mixer_devinfo_t
*);
221 static int eap1371_attach_codec(void *, struct ac97_codec_if
*);
222 static int eap1371_read_codec(void *, uint8_t, uint16_t *);
223 static int eap1371_write_codec(void *, uint8_t, uint16_t );
224 static int eap1371_reset_codec(void *);
226 static void eap_midi_close(void *);
227 static void eap_midi_getinfo(void *, struct midi_info
*);
228 static int eap_midi_open(void *, int, void (*)(void *, int),
229 void (*)(void *), void *);
230 static int eap_midi_output(void *, int);
231 static void eap_uart_txrdy(struct eap_softc
*);
234 static const struct audio_hw_if eap1370_hw_if
= {
251 eap1370_mixer_set_port
,
252 eap1370_mixer_get_port
,
253 eap1370_query_devinfo
,
256 eap_round_buffersize
,
265 static const struct audio_hw_if eap1371_hw_if
= {
282 eap1371_mixer_set_port
,
283 eap1371_mixer_get_port
,
284 eap1371_query_devinfo
,
287 eap_round_buffersize
,
297 static const struct midi_hw_if eap_midi_hw_if
= {
306 static struct audio_device eap_device
= {
312 #define EAP_NFORMATS 4
313 static const struct audio_format eap_formats
[EAP_NFORMATS
] = {
314 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 16, 16,
315 2, AUFMT_STEREO
, 0, {4000, 48000}},
316 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 16, 16,
317 1, AUFMT_MONAURAL
, 0, {4000, 48000}},
318 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 8, 8,
319 2, AUFMT_STEREO
, 0, {4000, 48000}},
320 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 8, 8,
321 1, AUFMT_MONAURAL
, 0, {4000, 48000}},
325 eap_match(device_t parent
, cfdata_t match
, void *aux
)
327 struct pci_attach_args
*pa
;
329 pa
= (struct pci_attach_args
*)aux
;
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
:
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
:
351 eap1370_write_codec(struct eap_softc
*sc
, int a
, int d
)
355 to
= EAP_WRITE_TIMEOUT
;
357 icss
= EREAD4(sc
, EAP_ICSS
);
358 DPRINTFN(5,("eap: codec %d prog: icss=0x%08x\n", a
, icss
));
360 printf("eap: timeout writing to codec\n");
363 } while(icss
& EAP_CWRIP
); /* XXX could use CSTAT here */
364 EWRITE4(sc
, EAP_CODEC
, EAP_SET_CODEC(a
, d
));
368 * Reading and writing the CODEC is very convoluted. This mimics the
369 * FreeBSD and Linux drivers.
373 eap1371_ready_codec(struct eap_softc
*sc
, uint8_t a
, uint32_t wd
)
378 for (to
= 0; to
< EAP_WRITE_TIMEOUT
; to
++) {
379 if (!(EREAD4(sc
, E1371_CODEC
) & E1371_CODEC_WIP
))
383 if (to
>= EAP_WRITE_TIMEOUT
)
384 aprint_error_dev(sc
->sc_dev
,
385 "eap1371_ready_codec timeout 1\n");
388 src
= eap1371_src_wait(sc
) & E1371_SRC_CTLMASK
;
389 EWRITE4(sc
, E1371_SRC
, src
| E1371_SRC_STATE_OK
);
391 for (to
= 0; to
< EAP_READ_TIMEOUT
; to
++) {
392 t
= EREAD4(sc
, E1371_SRC
);
393 if ((t
& E1371_SRC_STATE_MASK
) == 0)
397 if (to
>= EAP_READ_TIMEOUT
)
398 aprint_error_dev(sc
->sc_dev
,
399 "eap1371_ready_codec timeout 2\n");
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
)
407 if (to
>= EAP_READ_TIMEOUT
)
408 aprint_error_dev(sc
->sc_dev
,
409 "eap1371_ready_codec timeout 3\n");
411 EWRITE4(sc
, E1371_CODEC
, wd
);
413 eap1371_src_wait(sc
);
414 EWRITE4(sc
, E1371_SRC
, src
);
420 eap1371_read_codec(void *sc_
, uint8_t a
, uint16_t *d
)
422 struct eap_softc
*sc
;
427 eap1371_ready_codec(sc
, a
, E1371_SET_CODEC(a
, 0) | E1371_CODEC_READ
);
429 for (to
= 0; to
< EAP_WRITE_TIMEOUT
; to
++) {
430 if (!(EREAD4(sc
, E1371_CODEC
) & E1371_CODEC_WIP
))
433 if (to
> EAP_WRITE_TIMEOUT
)
434 aprint_error_dev(sc
->sc_dev
,
435 "eap1371_read_codec timeout 1\n");
437 for (to
= 0; to
< EAP_WRITE_TIMEOUT
; to
++) {
438 t
= EREAD4(sc
, E1371_CODEC
);
439 if (t
& E1371_CODEC_VALID
)
442 if (to
> EAP_WRITE_TIMEOUT
)
443 aprint_error_dev(sc
->sc_dev
, "eap1371_read_codec timeout 2\n");
447 DPRINTFN(10, ("eap1371: reading codec (%x) = %x\n", a
, *d
));
453 eap1371_write_codec(void *sc_
, uint8_t a
, uint16_t d
)
455 struct eap_softc
*sc
;
458 eap1371_ready_codec(sc
, a
, E1371_SET_CODEC(a
, d
));
460 DPRINTFN(10, ("eap1371: writing codec %x --> %x\n", d
, a
));
466 eap1371_src_wait(struct eap_softc
*sc
)
471 for (to
= 0; to
< EAP_READ_TIMEOUT
; to
++) {
472 src
= EREAD4(sc
, E1371_SRC
);
473 if (!(src
& E1371_SRC_RBUSY
))
477 aprint_error_dev(sc
->sc_dev
, "eap1371_src_wait timeout\n");
482 eap1371_src_read(struct eap_softc
*sc
, int a
)
487 src
= eap1371_src_wait(sc
) & E1371_SRC_CTLMASK
;
488 src
|= E1371_SRC_ADDR(a
);
489 EWRITE4(sc
, E1371_SRC
, src
| E1371_SRC_STATE_OK
);
491 t
= eap1371_src_wait(sc
);
492 if ((t
& E1371_SRC_STATE_MASK
) != E1371_SRC_STATE_OK
) {
493 for (to
= 0; to
< EAP_READ_TIMEOUT
; to
++) {
494 t
= EREAD4(sc
, E1371_SRC
);
495 if ((t
& E1371_SRC_STATE_MASK
) == E1371_SRC_STATE_OK
)
501 EWRITE4(sc
, E1371_SRC
, src
);
503 return t
& E1371_SRC_DATAMASK
;
507 eap1371_src_write(struct eap_softc
*sc
, int a
, int d
)
511 r
= eap1371_src_wait(sc
) & E1371_SRC_CTLMASK
;
512 r
|= E1371_SRC_RAMWE
| E1371_SRC_ADDR(a
) | E1371_SRC_DATA(d
);
513 EWRITE4(sc
, E1371_SRC
, r
);
517 eap1371_set_adc_rate(struct eap_softc
*sc
, int rate
)
523 /* Whatever, it works, so I'll leave it :) */
530 if ((1 << n
) & SRC_MAGIC
)
532 truncm
= ((21 * n
) - 1) | 1;
533 freq
= ((48000 << 15) / rate
) * n
;
537 out
= ESRC_SET_TRUNC((239 - truncm
) / 2);
541 out
= ESRC_SMF
| ESRC_SET_TRUNC((119 - truncm
) / 2);
543 out
|= ESRC_SET_N(n
);
545 eap1371_src_write(sc
, ESRC_ADC
+ESRC_TRUNC_N
, out
);
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
));
557 eap1371_set_dac_rate(struct eap_instance
*ei
, int rate
)
559 struct eap_softc
*sc
;
564 DPRINTFN(2, ("eap1371_set_dac_date: set rate for %d\n", ei
->index
));
565 sc
= device_private(ei
->parent
);
566 dac
= ei
->index
== EAP_DAC1
? ESRC_DAC1
: ESRC_DAC2
;
568 /* Whatever, it works, so I'll leave it :) */
574 freq
= ((rate
<< 15) + 1500) / 3000;
577 eap1371_src_wait(sc
);
578 r
= EREAD4(sc
, E1371_SRC
) & (E1371_SRC_DISABLE
|
579 E1371_SRC_DISP2
| E1371_SRC_DISP1
| E1371_SRC_DISREC
);
580 r
|= ei
->index
== EAP_DAC1
? E1371_SRC_DISP1
: E1371_SRC_DISP2
;
581 EWRITE4(sc
, E1371_SRC
, r
);
582 r
= eap1371_src_read(sc
, dac
+ ESRC_IREGS
) & 0x00ff;
583 eap1371_src_write(sc
, dac
+ ESRC_IREGS
, r
| ((freq
>> 5) & 0xfc00));
584 eap1371_src_write(sc
, dac
+ ESRC_VFF
, freq
& 0x7fff);
585 r
= EREAD4(sc
, E1371_SRC
) & (E1371_SRC_DISABLE
|
586 E1371_SRC_DISP2
| E1371_SRC_DISP1
| E1371_SRC_DISREC
);
587 r
&= ~(ei
->index
== EAP_DAC1
? E1371_SRC_DISP1
: E1371_SRC_DISP2
);
588 EWRITE4(sc
, E1371_SRC
, r
);
593 eap_attach(device_t parent
, device_t self
, void *aux
)
595 struct eap_softc
*sc
;
596 struct pci_attach_args
*pa
;
597 pci_chipset_tag_t pc
;
598 const struct audio_hw_if
*eap_hw_if
;
600 pci_intr_handle_t ih
;
605 int revision
, ct5880
;
608 struct eap_gameport_args gpargs
;
611 sc
= device_private(self
);
613 pa
= (struct pci_attach_args
*)aux
;
616 aprint_naive(": Audio controller\n");
618 /* Stash this away for detach */
621 /* Flag if we're "creative" */
622 sc
->sc_1371
= !(PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_ENSONIQ
&&
623 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_ENSONIQ_AUDIOPCI
);
626 * The vendor and product ID's are quite "interesting". Just
627 * trust the following and be happy.
629 pci_devinfo(pa
->pa_id
, pa
->pa_class
, 0, devinfo
, sizeof(devinfo
));
630 revision
= PCI_REVISION(pa
->pa_class
);
633 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_ENSONIQ
&&
634 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_ENSONIQ_CT5880
) {
637 case EAP_CT5880_C
: revstr
= "CT5880-C "; break;
638 case EAP_CT5880_D
: revstr
= "CT5880-D "; break;
639 case EAP_CT5880_E
: revstr
= "CT5880-E "; break;
643 case EAP_EV1938_A
: revstr
= "EV1938-A "; break;
644 case EAP_ES1373_A
: revstr
= "ES1373-A "; break;
645 case EAP_ES1373_B
: revstr
= "ES1373-B "; break;
646 case EAP_CT5880_A
: revstr
= "CT5880-A "; ct5880
=1;break;
647 case EAP_ES1373_8
: revstr
= "ES1373-8" ; ct5880
=1;break;
648 case EAP_ES1371_B
: revstr
= "ES1371-B "; break;
652 aprint_normal(": %s %s(rev. 0x%02x)\n", devinfo
, revstr
, revision
);
654 /* Map I/O register */
655 if (pci_mapreg_map(pa
, PCI_CBIO
, PCI_MAPREG_TYPE_IO
, 0,
656 &sc
->iot
, &sc
->ioh
, NULL
, &sc
->iosz
)) {
657 aprint_error_dev(sc
->sc_dev
, "can't map i/o space\n");
661 sc
->sc_dmatag
= pa
->pa_dmat
;
663 /* Enable the device. */
664 csr
= pci_conf_read(pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
);
665 pci_conf_write(pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
,
666 csr
| PCI_COMMAND_MASTER_ENABLE
);
668 /* Map and establish the interrupt. */
669 if (pci_intr_map(pa
, &ih
)) {
670 aprint_error_dev(sc
->sc_dev
, "couldn't map interrupt\n");
673 intrstr
= pci_intr_string(pc
, ih
);
674 sc
->sc_ih
= pci_intr_establish(pc
, ih
, IPL_AUDIO
, eap_intr
, sc
);
675 if (sc
->sc_ih
== NULL
) {
676 aprint_error_dev(sc
->sc_dev
, "couldn't establish interrupt");
678 aprint_error(" at %s", intrstr
);
682 aprint_normal_dev(self
, "interrupting at %s\n", intrstr
);
684 sc
->sc_ei
[EAP_I1
].parent
= self
;
685 sc
->sc_ei
[EAP_I1
].index
= EAP_DAC2
;
686 sc
->sc_ei
[EAP_I2
].parent
= self
;
687 sc
->sc_ei
[EAP_I2
].index
= EAP_DAC1
;
690 /* Enable interrupts and looping mode. */
691 /* enable the parts we need */
692 EWRITE4(sc
, EAP_SIC
, EAP_P2_INTR_EN
| EAP_R1_INTR_EN
);
693 EWRITE4(sc
, EAP_ICSC
, EAP_CDC_EN
);
696 /* normal operation */
697 /* select codec clocks */
698 eap1370_write_codec(sc
, AK_RESET
, AK_PD
);
699 eap1370_write_codec(sc
, AK_RESET
, AK_PD
| AK_NRST
);
700 eap1370_write_codec(sc
, AK_CS
, 0x0);
702 eap_hw_if
= &eap1370_hw_if
;
704 /* Enable all relevant mixer switches. */
705 ctl
.dev
= EAP_INPUT_SOURCE
;
706 ctl
.type
= AUDIO_MIXER_SET
;
707 ctl
.un
.mask
= 1 << EAP_VOICE_VOL
| 1 << EAP_FM_VOL
|
708 1 << EAP_CD_VOL
| 1 << EAP_LINE_VOL
| 1 << EAP_AUX_VOL
|
710 eap_hw_if
->set_port(&sc
->sc_ei
[EAP_I1
], &ctl
);
712 ctl
.type
= AUDIO_MIXER_VALUE
;
713 ctl
.un
.value
.num_channels
= 1;
714 for (ctl
.dev
= EAP_MASTER_VOL
; ctl
.dev
< EAP_MIC_VOL
;
716 ctl
.un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
] = VOL_0DB
;
717 eap_hw_if
->set_port(&sc
->sc_ei
[EAP_I1
], &ctl
);
719 ctl
.un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
] = 0;
720 eap_hw_if
->set_port(&sc
->sc_ei
[EAP_I1
], &ctl
);
721 ctl
.dev
= EAP_MIC_PREAMP
;
722 ctl
.type
= AUDIO_MIXER_ENUM
;
724 eap_hw_if
->set_port(&sc
->sc_ei
[EAP_I1
], &ctl
);
725 ctl
.dev
= EAP_RECORD_SOURCE
;
726 ctl
.type
= AUDIO_MIXER_SET
;
727 ctl
.un
.mask
= 1 << EAP_MIC_VOL
;
728 eap_hw_if
->set_port(&sc
->sc_ei
[EAP_I1
], &ctl
);
732 EWRITE4(sc
, EAP_SIC
, 0);
733 EWRITE4(sc
, EAP_ICSC
, 0);
734 EWRITE4(sc
, E1371_LEGACY
, 0);
737 EWRITE4(sc
, EAP_ICSS
, EAP_CT5880_AC97_RESET
);
738 /* Let codec wake up */
742 /* Reset from es1371's perspective */
743 EWRITE4(sc
, EAP_ICSC
, E1371_SYNC_RES
);
745 EWRITE4(sc
, EAP_ICSC
, 0);
748 * Must properly reprogram sample rate converter,
749 * or it locks up. Set some defaults for the life of the
750 * machine, and set up a sb default sample rate.
752 EWRITE4(sc
, E1371_SRC
, E1371_SRC_DISABLE
);
753 for (i
= 0; i
< 0x80; i
++)
754 eap1371_src_write(sc
, i
, 0);
755 eap1371_src_write(sc
, ESRC_DAC1
+ESRC_TRUNC_N
, ESRC_SET_N(16));
756 eap1371_src_write(sc
, ESRC_DAC2
+ESRC_TRUNC_N
, ESRC_SET_N(16));
757 eap1371_src_write(sc
, ESRC_DAC1
+ESRC_IREGS
, ESRC_SET_VFI(16));
758 eap1371_src_write(sc
, ESRC_DAC2
+ESRC_IREGS
, ESRC_SET_VFI(16));
759 eap1371_src_write(sc
, ESRC_ADC_VOLL
, ESRC_SET_ADC_VOL(16));
760 eap1371_src_write(sc
, ESRC_ADC_VOLR
, ESRC_SET_ADC_VOL(16));
761 eap1371_src_write(sc
, ESRC_DAC1_VOLL
, ESRC_SET_DAC_VOLI(1));
762 eap1371_src_write(sc
, ESRC_DAC1_VOLR
, ESRC_SET_DAC_VOLI(1));
763 eap1371_src_write(sc
, ESRC_DAC2_VOLL
, ESRC_SET_DAC_VOLI(1));
764 eap1371_src_write(sc
, ESRC_DAC2_VOLR
, ESRC_SET_DAC_VOLI(1));
765 eap1371_set_adc_rate(sc
, 22050);
766 eap1371_set_dac_rate(&sc
->sc_ei
[0], 22050);
767 eap1371_set_dac_rate(&sc
->sc_ei
[1], 22050);
769 EWRITE4(sc
, E1371_SRC
, 0);
773 /* Interrupt enable */
774 sc
->host_if
.arg
= sc
;
775 sc
->host_if
.attach
= eap1371_attach_codec
;
776 sc
->host_if
.read
= eap1371_read_codec
;
777 sc
->host_if
.write
= eap1371_write_codec
;
778 sc
->host_if
.reset
= eap1371_reset_codec
;
780 if (ac97_attach(&sc
->host_if
, self
) == 0) {
781 /* Interrupt enable */
782 EWRITE4(sc
, EAP_SIC
, EAP_P2_INTR_EN
| EAP_R1_INTR_EN
);
786 eap_hw_if
= &eap1371_hw_if
;
789 sc
->sc_ei
[EAP_I1
].ei_audiodev
=
790 audio_attach_mi(eap_hw_if
, &sc
->sc_ei
[EAP_I1
], sc
->sc_dev
);
792 #ifdef EAP_USE_BOTH_DACS
793 aprint_normal_dev(self
, "attaching secondary DAC\n");
794 sc
->sc_ei
[EAP_I2
].ei_audiodev
=
795 audio_attach_mi(eap_hw_if
, &sc
->sc_ei
[EAP_I2
], sc
->sc_dev
);
799 sc
->sc_mididev
= midi_attach_mi(&eap_midi_hw_if
, sc
, sc
->sc_dev
);
804 gpargs
.gpa_iot
= sc
->iot
;
805 gpargs
.gpa_ioh
= sc
->ioh
;
806 sc
->sc_gameport
= eap_joy_attach(sc
->sc_dev
, &gpargs
);
812 eap_detach(device_t self
, int flags
)
814 struct eap_softc
*sc
;
817 struct eap_gameport_args gpargs
;
819 sc
= device_private(self
);
820 if (sc
->sc_gameport
) {
821 gpargs
.gpa_iot
= sc
->iot
;
822 gpargs
.gpa_ioh
= sc
->ioh
;
823 res
= eap_joy_detach(sc
->sc_gameport
, &gpargs
);
828 sc
= device_private(self
);
831 if (sc
->sc_mididev
!= NULL
) {
832 res
= config_detach(sc
->sc_mididev
, 0);
837 #ifdef EAP_USE_BOTH_DACS
838 if (sc
->sc_ei
[EAP_I2
].ei_audiodev
!= NULL
) {
839 res
= config_detach(sc
->sc_ei
[EAP_I2
].ei_audiodev
, 0);
844 if (sc
->sc_ei
[EAP_I1
].ei_audiodev
!= NULL
) {
845 res
= config_detach(sc
->sc_ei
[EAP_I1
].ei_audiodev
, 0);
850 bus_space_unmap(sc
->iot
, sc
->ioh
, sc
->iosz
);
851 pci_intr_disestablish(sc
->sc_pc
, sc
->sc_ih
);
857 eap1371_attach_codec(void *sc_
, struct ac97_codec_if
*codec_if
)
859 struct eap_softc
*sc
;
862 sc
->codec_if
= codec_if
;
867 eap1371_reset_codec(void *sc_
)
869 struct eap_softc
*sc
;
875 icsc
= EREAD4(sc
, EAP_ICSC
);
876 EWRITE4(sc
, EAP_ICSC
, icsc
| E1371_SYNC_RES
);
878 EWRITE4(sc
, EAP_ICSC
, icsc
& ~E1371_SYNC_RES
);
888 struct eap_softc
*sc
;
892 intr
= EREAD4(sc
, EAP_ICSS
);
893 if (!(intr
& EAP_INTR
))
895 sic
= EREAD4(sc
, EAP_SIC
);
896 DPRINTFN(5, ("eap_intr: ICSS=0x%08x, SIC=0x%08x\n", intr
, sic
));
897 if (intr
& EAP_I_ADC
) {
900 * XXX This is a hack!
901 * The EAP chip sometimes generates the recording interrupt
902 * while it is still transferring the data. To make sure
903 * it has all arrived we busy wait until the count is right.
904 * The transfer we are waiting for is 8 longwords.
907 EWRITE4(sc
, EAP_MEMPAGE
, EAP_ADC_PAGE
);
908 s
= EREAD4(sc
, EAP_ADC_CSR
);
909 nw
= ((s
& 0xffff) + 1) >> 2; /* # of words in DMA */
911 while (((EREAD4(sc
, EAP_ADC_SIZE
) >> 16) + 8) % nw
== 0) {
914 printf("eapintr: DMA fix timeout");
918 /* Continue with normal interrupt handling. */
920 EWRITE4(sc
, EAP_SIC
, sic
& ~EAP_R1_INTR_EN
);
921 EWRITE4(sc
, EAP_SIC
, sic
| EAP_R1_INTR_EN
);
923 sc
->sc_rintr(sc
->sc_rarg
);
926 if (intr
& EAP_I_DAC2
) {
927 EWRITE4(sc
, EAP_SIC
, sic
& ~EAP_P2_INTR_EN
);
928 EWRITE4(sc
, EAP_SIC
, sic
| EAP_P2_INTR_EN
);
929 if (sc
->sc_ei
[EAP_DAC2
].ei_pintr
)
930 sc
->sc_ei
[EAP_DAC2
].ei_pintr(sc
->sc_ei
[EAP_DAC2
].ei_parg
);
933 if (intr
& EAP_I_DAC1
) {
934 EWRITE4(sc
, EAP_SIC
, sic
& ~EAP_P1_INTR_EN
);
935 EWRITE4(sc
, EAP_SIC
, sic
| EAP_P1_INTR_EN
);
936 if (sc
->sc_ei
[EAP_DAC1
].ei_pintr
)
937 sc
->sc_ei
[EAP_DAC1
].ei_pintr(sc
->sc_ei
[EAP_DAC1
].ei_parg
);
940 if (intr
& EAP_I_MCCB
)
941 panic("eap_intr: unexpected MCCB interrupt");
943 if (intr
& EAP_I_UART
) {
947 ustat
= EREAD1(sc
, EAP_UART_STATUS
);
949 if (ustat
& EAP_US_RXINT
) {
950 while (EREAD1(sc
, EAP_UART_STATUS
) & EAP_US_RXRDY
) {
951 data
= EREAD1(sc
, EAP_UART_DATA
);
952 sc
->sc_iintr(sc
->sc_arg
, data
);
956 if (ustat
& EAP_US_TXINT
)
964 eap_allocmem(struct eap_softc
*sc
, size_t size
, size_t align
, struct eap_dma
*p
)
969 error
= bus_dmamem_alloc(sc
->sc_dmatag
, p
->size
, align
, 0,
970 p
->segs
, sizeof(p
->segs
)/sizeof(p
->segs
[0]),
971 &p
->nsegs
, BUS_DMA_NOWAIT
);
975 error
= bus_dmamem_map(sc
->sc_dmatag
, p
->segs
, p
->nsegs
, p
->size
,
976 &p
->addr
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
);
980 error
= bus_dmamap_create(sc
->sc_dmatag
, p
->size
, 1, p
->size
,
981 0, BUS_DMA_NOWAIT
, &p
->map
);
985 error
= bus_dmamap_load(sc
->sc_dmatag
, p
->map
, p
->addr
, p
->size
, NULL
,
992 bus_dmamap_destroy(sc
->sc_dmatag
, p
->map
);
994 bus_dmamem_unmap(sc
->sc_dmatag
, p
->addr
, p
->size
);
996 bus_dmamem_free(sc
->sc_dmatag
, p
->segs
, p
->nsegs
);
1001 eap_freemem(struct eap_softc
*sc
, struct eap_dma
*p
)
1004 bus_dmamap_unload(sc
->sc_dmatag
, p
->map
);
1005 bus_dmamap_destroy(sc
->sc_dmatag
, p
->map
);
1006 bus_dmamem_unmap(sc
->sc_dmatag
, p
->addr
, p
->size
);
1007 bus_dmamem_free(sc
->sc_dmatag
, p
->segs
, p
->nsegs
);
1012 eap_open(void *addr
, int flags
)
1014 struct eap_instance
*ei
;
1017 /* there is only one ADC */
1018 if (ei
->index
== EAP_I2
&& flags
& FREAD
)
1025 eap_query_encoding(void *addr
, struct audio_encoding
*fp
)
1028 switch (fp
->index
) {
1030 strcpy(fp
->name
, AudioEulinear
);
1031 fp
->encoding
= AUDIO_ENCODING_ULINEAR
;
1036 strcpy(fp
->name
, AudioEmulaw
);
1037 fp
->encoding
= AUDIO_ENCODING_ULAW
;
1039 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1042 strcpy(fp
->name
, AudioEalaw
);
1043 fp
->encoding
= AUDIO_ENCODING_ALAW
;
1045 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1048 strcpy(fp
->name
, AudioEslinear
);
1049 fp
->encoding
= AUDIO_ENCODING_SLINEAR
;
1051 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1054 strcpy(fp
->name
, AudioEslinear_le
);
1055 fp
->encoding
= AUDIO_ENCODING_SLINEAR_LE
;
1060 strcpy(fp
->name
, AudioEulinear_le
);
1061 fp
->encoding
= AUDIO_ENCODING_ULINEAR_LE
;
1063 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1066 strcpy(fp
->name
, AudioEslinear_be
);
1067 fp
->encoding
= AUDIO_ENCODING_SLINEAR_BE
;
1069 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1072 strcpy(fp
->name
, AudioEulinear_be
);
1073 fp
->encoding
= AUDIO_ENCODING_ULINEAR_BE
;
1075 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
1083 eap_set_params(void *addr
, int setmode
, int usemode
,
1084 audio_params_t
*play
, audio_params_t
*rec
,
1085 stream_filter_list_t
*pfil
, stream_filter_list_t
*rfil
)
1087 struct eap_instance
*ei
;
1088 struct eap_softc
*sc
;
1089 struct audio_params
*p
;
1090 stream_filter_list_t
*fil
;
1095 sc
= device_private(ei
->parent
);
1097 * The es1370 only has one clock, so make the sample rates match.
1098 * This only applies for ADC/DAC2. The FM DAC is handled below.
1100 if (!sc
->sc_1371
&& ei
->index
== EAP_DAC2
) {
1101 if (play
->sample_rate
!= rec
->sample_rate
&&
1102 usemode
== (AUMODE_PLAY
| AUMODE_RECORD
)) {
1103 if (setmode
== AUMODE_PLAY
) {
1104 rec
->sample_rate
= play
->sample_rate
;
1105 setmode
|= AUMODE_RECORD
;
1106 } else if (setmode
== AUMODE_RECORD
) {
1107 play
->sample_rate
= rec
->sample_rate
;
1108 setmode
|= AUMODE_PLAY
;
1114 for (mode
= AUMODE_RECORD
; mode
!= -1;
1115 mode
= mode
== AUMODE_RECORD
? AUMODE_PLAY
: -1) {
1116 if ((setmode
& mode
) == 0)
1119 p
= mode
== AUMODE_PLAY
? play
: rec
;
1121 if (p
->sample_rate
< 4000 || p
->sample_rate
> 48000 ||
1122 (p
->precision
!= 8 && p
->precision
!= 16) ||
1123 (p
->channels
!= 1 && p
->channels
!= 2))
1126 fil
= mode
== AUMODE_PLAY
? pfil
: rfil
;
1127 i
= auconv_set_converter(eap_formats
, EAP_NFORMATS
,
1128 mode
, p
, FALSE
, fil
);
1134 eap1371_set_dac_rate(ei
, play
->sample_rate
);
1135 eap1371_set_adc_rate(sc
, rec
->sample_rate
);
1136 } else if (ei
->index
== EAP_DAC2
) {
1138 DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n",
1139 EREAD4(sc
, EAP_ICSC
)));
1140 div
= EREAD4(sc
, EAP_ICSC
) & ~EAP_PCLKBITS
;
1143 * The -2 isn't documented, but seemed to make the wall
1145 * what I expect. - mycroft
1147 if (usemode
== AUMODE_RECORD
)
1148 div
|= EAP_SET_PCLKDIV(EAP_XTAL_FREQ
/
1149 rec
->sample_rate
- 2);
1151 div
|= EAP_SET_PCLKDIV(EAP_XTAL_FREQ
/
1152 play
->sample_rate
- 2);
1154 div
|= EAP_CCB_INTRM
;
1157 * It is not obvious how to acknowledge MCCB interrupts, so
1158 * we had better not enable them.
1161 EWRITE4(sc
, EAP_ICSC
, div
);
1162 DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div
));
1165 * The FM DAC has only a few fixed-frequency choises, so
1166 * pick out the best candidate.
1168 div
= EREAD4(sc
, EAP_ICSC
);
1169 DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n", div
));
1171 div
&= ~EAP_WTSRSEL
;
1172 if (play
->sample_rate
< 8268)
1173 div
|= EAP_WTSRSEL_5
;
1174 else if (play
->sample_rate
< 16537)
1175 div
|= EAP_WTSRSEL_11
;
1176 else if (play
->sample_rate
< 33075)
1177 div
|= EAP_WTSRSEL_22
;
1179 div
|= EAP_WTSRSEL_44
;
1181 EWRITE4(sc
, EAP_ICSC
, div
);
1182 DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div
));
1189 eap_round_blocksize(void *addr
, int blk
, int mode
,
1190 const audio_params_t
*param
)
1193 return blk
& -32; /* keep good alignment */
1202 void (*intr
)(void *),
1204 const audio_params_t
*param
)
1206 struct eap_instance
*ei
;
1207 struct eap_softc
*sc
;
1213 sc
= device_private(ei
->parent
);
1216 panic("eap_trigger_output: already running");
1220 DPRINTFN(1, ("eap_trigger_output: sc=%p start=%p end=%p "
1221 "blksize=%d intr=%p(%p)\n", addr
, start
, end
, blksize
, intr
, arg
));
1222 ei
->ei_pintr
= intr
;
1225 sic
= EREAD4(sc
, EAP_SIC
);
1226 sic
&= ~(EAP_S_EB(ei
->index
) | EAP_S_MB(ei
->index
) | EAP_INC_BITS
);
1228 if (ei
->index
== EAP_DAC2
)
1229 sic
|= EAP_SET_P2_ST_INC(0)
1230 | EAP_SET_P2_END_INC(param
->precision
/ 8);
1233 if (param
->precision
== 16) {
1234 sic
|= EAP_S_EB(ei
->index
);
1237 if (param
->channels
== 2) {
1238 sic
|= EAP_S_MB(ei
->index
);
1241 EWRITE4(sc
, EAP_SIC
, sic
& ~EAP_P_INTR_EN(ei
->index
));
1242 EWRITE4(sc
, EAP_SIC
, sic
| EAP_P_INTR_EN(ei
->index
));
1244 for (p
= sc
->sc_dmas
; p
&& KERNADDR(p
) != start
; p
= p
->next
)
1247 printf("eap_trigger_output: bad addr %p\n", start
);
1251 if (ei
->index
== EAP_DAC2
) {
1252 DPRINTF(("eap_trigger_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
1254 (int)EAP_SET_SIZE(0,
1255 (((char *)end
- (char *)start
) >> 2) - 1)));
1256 EWRITE4(sc
, EAP_MEMPAGE
, EAP_DAC_PAGE
);
1257 EWRITE4(sc
, EAP_DAC2_ADDR
, DMAADDR(p
));
1258 EWRITE4(sc
, EAP_DAC2_SIZE
,
1260 ((char *)end
- (char *)start
) >> 2) - 1);
1261 EWRITE4(sc
, EAP_DAC2_CSR
, (blksize
>> sampshift
) - 1);
1262 } else if (ei
->index
== EAP_DAC1
) {
1263 DPRINTF(("eap_trigger_output: DAC1_ADDR=0x%x, DAC1_SIZE=0x%x\n",
1265 (int)EAP_SET_SIZE(0,
1266 (((char *)end
- (char *)start
) >> 2) - 1)));
1267 EWRITE4(sc
, EAP_MEMPAGE
, EAP_DAC_PAGE
);
1268 EWRITE4(sc
, EAP_DAC1_ADDR
, DMAADDR(p
));
1269 EWRITE4(sc
, EAP_DAC1_SIZE
,
1271 ((char *)end
- (char *)start
) >> 2) - 1);
1272 EWRITE4(sc
, EAP_DAC1_CSR
, (blksize
>> sampshift
) - 1);
1276 panic("eap_trigger_output: impossible instance %d", ei
->index
);
1280 EWRITE4(sc
, E1371_SRC
, 0);
1282 icsc
= EREAD4(sc
, EAP_ICSC
);
1283 icsc
|= EAP_DAC_EN(ei
->index
);
1284 EWRITE4(sc
, EAP_ICSC
, icsc
);
1286 DPRINTFN(1, ("eap_trigger_output: set ICSC = 0x%08x\n", icsc
));
1297 void (*intr
)(void *),
1299 const audio_params_t
*param
)
1301 struct eap_instance
*ei
;
1302 struct eap_softc
*sc
;
1308 sc
= device_private(ei
->parent
);
1311 panic("eap_trigger_input: already running");
1315 DPRINTFN(1, ("eap_trigger_input: ei=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
1316 addr
, start
, end
, blksize
, intr
, arg
));
1317 sc
->sc_rintr
= intr
;
1320 sic
= EREAD4(sc
, EAP_SIC
);
1321 sic
&= ~(EAP_R1_S_EB
| EAP_R1_S_MB
);
1323 if (param
->precision
== 16) {
1327 if (param
->channels
== 2) {
1331 EWRITE4(sc
, EAP_SIC
, sic
& ~EAP_R1_INTR_EN
);
1332 EWRITE4(sc
, EAP_SIC
, sic
| EAP_R1_INTR_EN
);
1334 for (p
= sc
->sc_dmas
; p
&& KERNADDR(p
) != start
; p
= p
->next
)
1337 printf("eap_trigger_input: bad addr %p\n", start
);
1341 DPRINTF(("eap_trigger_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
1343 (int)EAP_SET_SIZE(0, (((char *)end
- (char *)start
) >> 2) - 1)));
1344 EWRITE4(sc
, EAP_MEMPAGE
, EAP_ADC_PAGE
);
1345 EWRITE4(sc
, EAP_ADC_ADDR
, DMAADDR(p
));
1346 EWRITE4(sc
, EAP_ADC_SIZE
,
1347 EAP_SET_SIZE(0, (((char *)end
- (char *)start
) >> 2) - 1));
1349 EWRITE4(sc
, EAP_ADC_CSR
, (blksize
>> sampshift
) - 1);
1352 EWRITE4(sc
, E1371_SRC
, 0);
1354 icsc
= EREAD4(sc
, EAP_ICSC
);
1356 EWRITE4(sc
, EAP_ICSC
, icsc
);
1358 DPRINTFN(1, ("eap_trigger_input: set ICSC = 0x%08x\n", icsc
));
1364 eap_halt_output(void *addr
)
1366 struct eap_instance
*ei
;
1367 struct eap_softc
*sc
;
1370 DPRINTF(("eap: eap_halt_output\n"));
1372 sc
= device_private(ei
->parent
);
1373 icsc
= EREAD4(sc
, EAP_ICSC
);
1374 EWRITE4(sc
, EAP_ICSC
, icsc
& ~(EAP_DAC_EN(ei
->index
)));
1384 eap_halt_input(void *addr
)
1386 struct eap_instance
*ei
;
1387 struct eap_softc
*sc
;
1390 #define EAP_USE_FMDAC_ALSO
1391 DPRINTF(("eap: eap_halt_input\n"));
1393 sc
= device_private(ei
->parent
);
1394 icsc
= EREAD4(sc
, EAP_ICSC
);
1395 EWRITE4(sc
, EAP_ICSC
, icsc
& ~EAP_ADC_EN
);
1405 eap_getdev(void *addr
, struct audio_device
*retp
)
1413 eap1371_mixer_set_port(void *addr
, mixer_ctrl_t
*cp
)
1415 struct eap_instance
*ei
;
1416 struct eap_softc
*sc
;
1419 sc
= device_private(ei
->parent
);
1420 return sc
->codec_if
->vtbl
->mixer_set_port(sc
->codec_if
, cp
);
1424 eap1371_mixer_get_port(void *addr
, mixer_ctrl_t
*cp
)
1426 struct eap_instance
*ei
;
1427 struct eap_softc
*sc
;
1430 sc
= device_private(ei
->parent
);
1431 return sc
->codec_if
->vtbl
->mixer_get_port(sc
->codec_if
, cp
);
1435 eap1371_query_devinfo(void *addr
, mixer_devinfo_t
*dip
)
1437 struct eap_instance
*ei
;
1438 struct eap_softc
*sc
;
1441 sc
= device_private(ei
->parent
);
1442 return sc
->codec_if
->vtbl
->query_devinfo(sc
->codec_if
, dip
);
1446 eap1370_set_mixer(struct eap_softc
*sc
, int a
, int d
)
1448 eap1370_write_codec(sc
, a
, d
);
1451 DPRINTFN(1, ("eap1370_mixer_set_port port 0x%02x = 0x%02x\n", a
, d
));
1455 eap1370_mixer_set_port(void *addr
, mixer_ctrl_t
*cp
)
1457 struct eap_instance
*ei
;
1458 struct eap_softc
*sc
;
1459 int lval
, rval
, l
, r
, la
, ra
;
1460 int l1
, r1
, l2
, r2
, m
, o1
, o2
;
1463 sc
= device_private(ei
->parent
);
1464 if (cp
->dev
== EAP_RECORD_SOURCE
) {
1465 if (cp
->type
!= AUDIO_MIXER_SET
)
1467 m
= sc
->sc_record_source
= cp
->un
.mask
;
1468 l1
= l2
= r1
= r2
= 0;
1469 if (m
& (1 << EAP_VOICE_VOL
))
1470 l2
|= AK_M_VOICE
, r2
|= AK_M_VOICE
;
1471 if (m
& (1 << EAP_FM_VOL
))
1472 l1
|= AK_M_FM_L
, r1
|= AK_M_FM_R
;
1473 if (m
& (1 << EAP_CD_VOL
))
1474 l1
|= AK_M_CD_L
, r1
|= AK_M_CD_R
;
1475 if (m
& (1 << EAP_LINE_VOL
))
1476 l1
|= AK_M_LINE_L
, r1
|= AK_M_LINE_R
;
1477 if (m
& (1 << EAP_AUX_VOL
))
1478 l2
|= AK_M2_AUX_L
, r2
|= AK_M2_AUX_R
;
1479 if (m
& (1 << EAP_MIC_VOL
))
1480 l2
|= AK_M_TMIC
, r2
|= AK_M_TMIC
;
1481 eap1370_set_mixer(sc
, AK_IN_MIXER1_L
, l1
);
1482 eap1370_set_mixer(sc
, AK_IN_MIXER1_R
, r1
);
1483 eap1370_set_mixer(sc
, AK_IN_MIXER2_L
, l2
);
1484 eap1370_set_mixer(sc
, AK_IN_MIXER2_R
, r2
);
1487 if (cp
->dev
== EAP_INPUT_SOURCE
) {
1488 if (cp
->type
!= AUDIO_MIXER_SET
)
1490 m
= sc
->sc_input_source
= cp
->un
.mask
;
1492 if (m
& (1 << EAP_VOICE_VOL
))
1493 o2
|= AK_M_VOICE_L
| AK_M_VOICE_R
;
1494 if (m
& (1 << EAP_FM_VOL
))
1495 o1
|= AK_M_FM_L
| AK_M_FM_R
;
1496 if (m
& (1 << EAP_CD_VOL
))
1497 o1
|= AK_M_CD_L
| AK_M_CD_R
;
1498 if (m
& (1 << EAP_LINE_VOL
))
1499 o1
|= AK_M_LINE_L
| AK_M_LINE_R
;
1500 if (m
& (1 << EAP_AUX_VOL
))
1501 o2
|= AK_M_AUX_L
| AK_M_AUX_R
;
1502 if (m
& (1 << EAP_MIC_VOL
))
1504 eap1370_set_mixer(sc
, AK_OUT_MIXER1
, o1
);
1505 eap1370_set_mixer(sc
, AK_OUT_MIXER2
, o2
);
1508 if (cp
->dev
== EAP_MIC_PREAMP
) {
1509 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1511 if (cp
->un
.ord
!= 0 && cp
->un
.ord
!= 1)
1513 sc
->sc_mic_preamp
= cp
->un
.ord
;
1514 eap1370_set_mixer(sc
, AK_MGAIN
, cp
->un
.ord
);
1517 if (cp
->type
!= AUDIO_MIXER_VALUE
)
1519 if (cp
->un
.value
.num_channels
== 1)
1520 lval
= rval
= cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
];
1521 else if (cp
->un
.value
.num_channels
== 2) {
1522 lval
= cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_LEFT
];
1523 rval
= cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_RIGHT
];
1528 case EAP_MASTER_VOL
:
1529 l
= VOL_TO_ATT5(lval
);
1530 r
= VOL_TO_ATT5(rval
);
1535 if (cp
->un
.value
.num_channels
!= 1)
1559 l
= VOL_TO_GAIN5(lval
);
1560 r
= VOL_TO_GAIN5(rval
);
1565 eap1370_set_mixer(sc
, la
, l
);
1567 eap1370_set_mixer(sc
, ra
, r
);
1573 eap1370_mixer_get_port(void *addr
, mixer_ctrl_t
*cp
)
1575 struct eap_instance
*ei
;
1576 struct eap_softc
*sc
;
1580 sc
= device_private(ei
->parent
);
1582 case EAP_RECORD_SOURCE
:
1583 if (cp
->type
!= AUDIO_MIXER_SET
)
1585 cp
->un
.mask
= sc
->sc_record_source
;
1587 case EAP_INPUT_SOURCE
:
1588 if (cp
->type
!= AUDIO_MIXER_SET
)
1590 cp
->un
.mask
= sc
->sc_input_source
;
1592 case EAP_MIC_PREAMP
:
1593 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1595 cp
->un
.ord
= sc
->sc_mic_preamp
;
1597 case EAP_MASTER_VOL
:
1598 l
= ATT5_TO_VOL(sc
->sc_port
[AK_MASTER_L
]);
1599 r
= ATT5_TO_VOL(sc
->sc_port
[AK_MASTER_R
]);
1602 if (cp
->un
.value
.num_channels
!= 1)
1626 l
= GAIN5_TO_VOL(sc
->sc_port
[la
]);
1627 r
= GAIN5_TO_VOL(sc
->sc_port
[ra
]);
1632 if (cp
->un
.value
.num_channels
== 1)
1633 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
] = (l
+r
) / 2;
1634 else if (cp
->un
.value
.num_channels
== 2) {
1635 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_LEFT
] = l
;
1636 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_RIGHT
] = r
;
1643 eap1370_query_devinfo(void *addr
, mixer_devinfo_t
*dip
)
1646 switch (dip
->index
) {
1647 case EAP_MASTER_VOL
:
1648 dip
->type
= AUDIO_MIXER_VALUE
;
1649 dip
->mixer_class
= EAP_OUTPUT_CLASS
;
1650 dip
->prev
= dip
->next
= AUDIO_MIXER_LAST
;
1651 strcpy(dip
->label
.name
, AudioNmaster
);
1652 dip
->un
.v
.num_channels
= 2;
1653 dip
->un
.v
.delta
= 8;
1654 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
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
, AudioNdac
);
1662 dip
->un
.v
.num_channels
= 2;
1663 dip
->un
.v
.delta
= 8;
1664 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1667 dip
->type
= AUDIO_MIXER_VALUE
;
1668 dip
->mixer_class
= EAP_INPUT_CLASS
;
1669 dip
->prev
= AUDIO_MIXER_LAST
;
1670 dip
->next
= AUDIO_MIXER_LAST
;
1671 strcpy(dip
->label
.name
, AudioNfmsynth
);
1672 dip
->un
.v
.num_channels
= 2;
1673 dip
->un
.v
.delta
= 8;
1674 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1677 dip
->type
= AUDIO_MIXER_VALUE
;
1678 dip
->mixer_class
= EAP_INPUT_CLASS
;
1679 dip
->prev
= AUDIO_MIXER_LAST
;
1680 dip
->next
= AUDIO_MIXER_LAST
;
1681 strcpy(dip
->label
.name
, AudioNcd
);
1682 dip
->un
.v
.num_channels
= 2;
1683 dip
->un
.v
.delta
= 8;
1684 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1687 dip
->type
= AUDIO_MIXER_VALUE
;
1688 dip
->mixer_class
= EAP_INPUT_CLASS
;
1689 dip
->prev
= AUDIO_MIXER_LAST
;
1690 dip
->next
= AUDIO_MIXER_LAST
;
1691 strcpy(dip
->label
.name
, AudioNline
);
1692 dip
->un
.v
.num_channels
= 2;
1693 dip
->un
.v
.delta
= 8;
1694 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1697 dip
->type
= AUDIO_MIXER_VALUE
;
1698 dip
->mixer_class
= EAP_INPUT_CLASS
;
1699 dip
->prev
= AUDIO_MIXER_LAST
;
1700 dip
->next
= AUDIO_MIXER_LAST
;
1701 strcpy(dip
->label
.name
, AudioNaux
);
1702 dip
->un
.v
.num_channels
= 2;
1703 dip
->un
.v
.delta
= 8;
1704 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1707 dip
->type
= AUDIO_MIXER_VALUE
;
1708 dip
->mixer_class
= EAP_INPUT_CLASS
;
1709 dip
->prev
= AUDIO_MIXER_LAST
;
1710 dip
->next
= EAP_MIC_PREAMP
;
1711 strcpy(dip
->label
.name
, AudioNmicrophone
);
1712 dip
->un
.v
.num_channels
= 1;
1713 dip
->un
.v
.delta
= 8;
1714 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1716 case EAP_RECORD_SOURCE
:
1717 dip
->mixer_class
= EAP_RECORD_CLASS
;
1718 dip
->prev
= dip
->next
= AUDIO_MIXER_LAST
;
1719 strcpy(dip
->label
.name
, AudioNsource
);
1720 dip
->type
= AUDIO_MIXER_SET
;
1721 dip
->un
.s
.num_mem
= 6;
1722 strcpy(dip
->un
.s
.member
[0].label
.name
, AudioNmicrophone
);
1723 dip
->un
.s
.member
[0].mask
= 1 << EAP_MIC_VOL
;
1724 strcpy(dip
->un
.s
.member
[1].label
.name
, AudioNcd
);
1725 dip
->un
.s
.member
[1].mask
= 1 << EAP_CD_VOL
;
1726 strcpy(dip
->un
.s
.member
[2].label
.name
, AudioNline
);
1727 dip
->un
.s
.member
[2].mask
= 1 << EAP_LINE_VOL
;
1728 strcpy(dip
->un
.s
.member
[3].label
.name
, AudioNfmsynth
);
1729 dip
->un
.s
.member
[3].mask
= 1 << EAP_FM_VOL
;
1730 strcpy(dip
->un
.s
.member
[4].label
.name
, AudioNaux
);
1731 dip
->un
.s
.member
[4].mask
= 1 << EAP_AUX_VOL
;
1732 strcpy(dip
->un
.s
.member
[5].label
.name
, AudioNdac
);
1733 dip
->un
.s
.member
[5].mask
= 1 << EAP_VOICE_VOL
;
1735 case EAP_INPUT_SOURCE
:
1736 dip
->mixer_class
= EAP_INPUT_CLASS
;
1737 dip
->prev
= dip
->next
= AUDIO_MIXER_LAST
;
1738 strcpy(dip
->label
.name
, AudioNsource
);
1739 dip
->type
= AUDIO_MIXER_SET
;
1740 dip
->un
.s
.num_mem
= 6;
1741 strcpy(dip
->un
.s
.member
[0].label
.name
, AudioNmicrophone
);
1742 dip
->un
.s
.member
[0].mask
= 1 << EAP_MIC_VOL
;
1743 strcpy(dip
->un
.s
.member
[1].label
.name
, AudioNcd
);
1744 dip
->un
.s
.member
[1].mask
= 1 << EAP_CD_VOL
;
1745 strcpy(dip
->un
.s
.member
[2].label
.name
, AudioNline
);
1746 dip
->un
.s
.member
[2].mask
= 1 << EAP_LINE_VOL
;
1747 strcpy(dip
->un
.s
.member
[3].label
.name
, AudioNfmsynth
);
1748 dip
->un
.s
.member
[3].mask
= 1 << EAP_FM_VOL
;
1749 strcpy(dip
->un
.s
.member
[4].label
.name
, AudioNaux
);
1750 dip
->un
.s
.member
[4].mask
= 1 << EAP_AUX_VOL
;
1751 strcpy(dip
->un
.s
.member
[5].label
.name
, AudioNdac
);
1752 dip
->un
.s
.member
[5].mask
= 1 << EAP_VOICE_VOL
;
1754 case EAP_MIC_PREAMP
:
1755 dip
->type
= AUDIO_MIXER_ENUM
;
1756 dip
->mixer_class
= EAP_INPUT_CLASS
;
1757 dip
->prev
= EAP_MIC_VOL
;
1758 dip
->next
= AUDIO_MIXER_LAST
;
1759 strcpy(dip
->label
.name
, AudioNpreamp
);
1760 dip
->un
.e
.num_mem
= 2;
1761 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1762 dip
->un
.e
.member
[0].ord
= 0;
1763 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1764 dip
->un
.e
.member
[1].ord
= 1;
1766 case EAP_OUTPUT_CLASS
:
1767 dip
->type
= AUDIO_MIXER_CLASS
;
1768 dip
->mixer_class
= EAP_OUTPUT_CLASS
;
1769 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1770 strcpy(dip
->label
.name
, AudioCoutputs
);
1772 case EAP_RECORD_CLASS
:
1773 dip
->type
= AUDIO_MIXER_CLASS
;
1774 dip
->mixer_class
= EAP_RECORD_CLASS
;
1775 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1776 strcpy(dip
->label
.name
, AudioCrecord
);
1778 case EAP_INPUT_CLASS
:
1779 dip
->type
= AUDIO_MIXER_CLASS
;
1780 dip
->mixer_class
= EAP_INPUT_CLASS
;
1781 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1782 strcpy(dip
->label
.name
, AudioCinputs
);
1789 eap_malloc(void *addr
, int direction
, size_t size
,
1790 struct malloc_type
*pool
, int flags
)
1792 struct eap_instance
*ei
;
1793 struct eap_softc
*sc
;
1797 p
= malloc(sizeof(*p
), pool
, flags
);
1801 sc
= device_private(ei
->parent
);
1802 error
= eap_allocmem(sc
, size
, 16, p
);
1807 p
->next
= sc
->sc_dmas
;
1813 eap_free(void *addr
, void *ptr
, struct malloc_type
*pool
)
1815 struct eap_instance
*ei
;
1816 struct eap_softc
*sc
;
1817 struct eap_dma
**pp
, *p
;
1820 sc
= device_private(ei
->parent
);
1821 for (pp
= &sc
->sc_dmas
; (p
= *pp
) != NULL
; pp
= &p
->next
) {
1822 if (KERNADDR(p
) == ptr
) {
1832 eap_round_buffersize(void *addr
, int direction
, size_t size
)
1839 eap_mappage(void *addr
, void *mem
, off_t off
, int prot
)
1841 struct eap_instance
*ei
;
1842 struct eap_softc
*sc
;
1848 sc
= device_private(ei
->parent
);
1849 for (p
= sc
->sc_dmas
; p
&& KERNADDR(p
) != mem
; p
= p
->next
)
1853 return bus_dmamem_mmap(sc
->sc_dmatag
, p
->segs
, p
->nsegs
,
1854 off
, prot
, BUS_DMA_WAITOK
);
1858 eap_get_props(void *addr
)
1861 return AUDIO_PROP_MMAP
| AUDIO_PROP_INDEPENDENT
|
1862 AUDIO_PROP_FULLDUPLEX
;
1867 eap_midi_open(void *addr
, int flags
,
1868 void (*iintr
)(void *, int),
1869 void (*ointr
)(void *),
1872 struct eap_softc
*sc
;
1878 EWRITE4(sc
, EAP_ICSC
, EREAD4(sc
, EAP_ICSC
) | EAP_UART_EN
);
1880 if (flags
& FREAD
) {
1881 uctrl
|= EAP_UC_RXINTEN
;
1882 sc
->sc_iintr
= iintr
;
1885 sc
->sc_ointr
= ointr
;
1886 EWRITE1(sc
, EAP_UART_CONTROL
, uctrl
);
1892 eap_midi_close(void *addr
)
1894 struct eap_softc
*sc
;
1897 tsleep(sc
, PWAIT
, "eapclm", hz
/10); /* give uart a chance to drain */
1898 EWRITE1(sc
, EAP_UART_CONTROL
, 0);
1899 EWRITE4(sc
, EAP_ICSC
, EREAD4(sc
, EAP_ICSC
) & ~EAP_UART_EN
);
1906 eap_midi_output(void *addr
, int d
)
1908 struct eap_softc
*sc
;
1912 EWRITE1(sc
, EAP_UART_DATA
, d
);
1914 uctrl
= EAP_UC_TXINTEN
;
1916 uctrl
|= EAP_UC_RXINTEN
;
1918 * This is a write-only register, so we have to remember the right
1919 * value of RXINTEN as well as setting TXINTEN. But if we are open
1920 * for reading, it will always be correct to set RXINTEN here; only
1921 * during service of a receive interrupt could it be momentarily
1922 * toggled off, and whether we got here from the top half or from
1923 * an interrupt, that won't be the current state.
1925 EWRITE1(sc
, EAP_UART_CONTROL
, uctrl
);
1930 eap_midi_getinfo(void *addr
, struct midi_info
*mi
)
1932 mi
->name
= "AudioPCI MIDI UART";
1933 mi
->props
= MIDI_PROP_CAN_INPUT
| MIDI_PROP_OUT_INTR
;
1937 eap_uart_txrdy(struct eap_softc
*sc
)
1942 uctrl
= EAP_UC_RXINTEN
;
1943 EWRITE1(sc
, EAP_UART_CONTROL
, uctrl
);
1944 sc
->sc_ointr(sc
->sc_arg
);