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