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