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