eap.c revision 1.27 1 1.27 kleink /* $NetBSD: eap.c,v 1.27 1999/09/01 07:32:31 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 mixer_ctrl_t ctl;
394 1.1 augustss
395 1.27 kleink printf(": Ensoniq AudioPCI (rev. 0x%02x)\n",
396 1.27 kleink PCI_REVISION(pa->pa_class));
397 1.1 augustss
398 1.1 augustss /* Map I/O register */
399 1.1 augustss if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
400 1.1 augustss &sc->iot, &sc->ioh, NULL, NULL)) {
401 1.1 augustss printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
402 1.1 augustss return;
403 1.1 augustss }
404 1.1 augustss
405 1.1 augustss sc->sc_dmatag = pa->pa_dmat;
406 1.1 augustss
407 1.1 augustss /* Enable the device. */
408 1.1 augustss csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
409 1.1 augustss pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
410 1.1 augustss csr | PCI_COMMAND_MASTER_ENABLE);
411 1.1 augustss
412 1.1 augustss /* Map and establish the interrupt. */
413 1.1 augustss if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
414 1.1 augustss pa->pa_intrline, &ih)) {
415 1.1 augustss printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
416 1.1 augustss return;
417 1.1 augustss }
418 1.1 augustss intrstr = pci_intr_string(pc, ih);
419 1.1 augustss sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, eap_intr, sc);
420 1.1 augustss if (sc->sc_ih == NULL) {
421 1.1 augustss printf("%s: couldn't establish interrupt",
422 1.1 augustss sc->sc_dev.dv_xname);
423 1.1 augustss if (intrstr != NULL)
424 1.1 augustss printf(" at %s", intrstr);
425 1.1 augustss printf("\n");
426 1.1 augustss return;
427 1.1 augustss }
428 1.1 augustss printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
429 1.1 augustss
430 1.1 augustss /* Enable interrupts and looping mode. */
431 1.9 mycroft EWRITE4(sc, EAP_SIC, EAP_P2_INTR_EN | EAP_R1_INTR_EN);
432 1.9 mycroft EWRITE4(sc, EAP_ICSC, EAP_CDC_EN); /* enable the parts we need */
433 1.1 augustss
434 1.1 augustss eap_write_codec(sc, AK_RESET, AK_PD); /* reset codec */
435 1.1 augustss eap_write_codec(sc, AK_RESET, AK_PD | AK_NRST); /* normal operation */
436 1.1 augustss eap_write_codec(sc, AK_CS, 0x0); /* select codec clocks */
437 1.8 augustss
438 1.1 augustss /* Enable all relevant mixer switches. */
439 1.8 augustss ctl.dev = EAP_OUTPUT_SELECT;
440 1.8 augustss ctl.type = AUDIO_MIXER_SET;
441 1.8 augustss ctl.un.mask = 1 << EAP_VOICE_VOL | 1 << EAP_FM_VOL | 1 << EAP_CD_VOL |
442 1.8 augustss 1 << EAP_LINE_VOL | 1 << EAP_AUX_VOL | 1 << EAP_MIC_VOL;
443 1.8 augustss eap_mixer_set_port(sc, &ctl);
444 1.8 augustss
445 1.1 augustss ctl.type = AUDIO_MIXER_VALUE;
446 1.1 augustss ctl.un.value.num_channels = 1;
447 1.1 augustss for (ctl.dev = EAP_MASTER_VOL; ctl.dev < EAP_MIC_VOL; ctl.dev++) {
448 1.1 augustss ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = VOL_0DB;
449 1.1 augustss eap_mixer_set_port(sc, &ctl);
450 1.1 augustss }
451 1.1 augustss ctl.un.value.level[AUDIO_MIXER_LEVEL_MONO] = 0;
452 1.1 augustss eap_mixer_set_port(sc, &ctl); /* set the mic to 0 */
453 1.12 mycroft ctl.dev = EAP_MIC_PREAMP;
454 1.12 mycroft ctl.type = AUDIO_MIXER_ENUM;
455 1.12 mycroft ctl.un.ord = 0;
456 1.12 mycroft eap_mixer_set_port(sc, &ctl);
457 1.1 augustss ctl.dev = EAP_RECORD_SOURCE;
458 1.1 augustss ctl.type = AUDIO_MIXER_SET;
459 1.1 augustss ctl.un.mask = 1 << EAP_MIC_VOL;
460 1.1 augustss eap_mixer_set_port(sc, &ctl);
461 1.1 augustss
462 1.16 augustss audio_attach_mi(&eap_hw_if, sc, &sc->sc_dev);
463 1.1 augustss }
464 1.1 augustss
465 1.1 augustss int
466 1.1 augustss eap_intr(p)
467 1.1 augustss void *p;
468 1.1 augustss {
469 1.1 augustss struct eap_softc *sc = p;
470 1.1 augustss u_int32_t intr, sic;
471 1.1 augustss
472 1.9 mycroft intr = EREAD4(sc, EAP_ICSS);
473 1.9 mycroft if (!(intr & EAP_INTR))
474 1.9 mycroft return (0);
475 1.1 augustss sic = EREAD4(sc, EAP_SIC);
476 1.1 augustss DPRINTFN(5, ("eap_intr: ICSS=0x%08x, SIC=0x%08x\n", intr, sic));
477 1.9 mycroft if (intr & EAP_I_ADC) {
478 1.9 mycroft /*
479 1.9 mycroft * XXX This is a hack!
480 1.9 mycroft * The EAP chip sometimes generates the recording interrupt
481 1.9 mycroft * while it is still transferring the data. To make sure
482 1.9 mycroft * it has all arrived we busy wait until the count is right.
483 1.9 mycroft * The transfer we are waiting for is 8 longwords.
484 1.9 mycroft */
485 1.9 mycroft int s, nw, n;
486 1.9 mycroft EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
487 1.9 mycroft s = EREAD4(sc, EAP_ADC_CSR);
488 1.9 mycroft nw = ((s & 0xffff) + 1) >> 2; /* # of words in DMA */
489 1.9 mycroft n = 0;
490 1.9 mycroft while (((EREAD4(sc, EAP_ADC_SIZE) >> 16) + 8) % nw == 0) {
491 1.9 mycroft delay(10);
492 1.9 mycroft if (++n > 100) {
493 1.9 mycroft printf("eapintr: dma fix timeout");
494 1.9 mycroft break;
495 1.9 mycroft }
496 1.9 mycroft }
497 1.9 mycroft /* Continue with normal interrupt handling. */
498 1.1 augustss EWRITE4(sc, EAP_SIC, sic & ~EAP_R1_INTR_EN);
499 1.1 augustss EWRITE4(sc, EAP_SIC, sic);
500 1.9 mycroft if (sc->sc_rintr)
501 1.9 mycroft sc->sc_rintr(sc->sc_rarg);
502 1.9 mycroft }
503 1.9 mycroft if (intr & EAP_I_DAC2) {
504 1.1 augustss EWRITE4(sc, EAP_SIC, sic & ~EAP_P2_INTR_EN);
505 1.1 augustss EWRITE4(sc, EAP_SIC, sic);
506 1.9 mycroft if (sc->sc_pintr)
507 1.9 mycroft sc->sc_pintr(sc->sc_parg);
508 1.9 mycroft }
509 1.1 augustss return (1);
510 1.1 augustss }
511 1.1 augustss
512 1.1 augustss int
513 1.1 augustss eap_allocmem(sc, size, align, p)
514 1.1 augustss struct eap_softc *sc;
515 1.1 augustss size_t size;
516 1.1 augustss size_t align;
517 1.9 mycroft struct eap_dma *p;
518 1.1 augustss {
519 1.1 augustss int error;
520 1.1 augustss
521 1.1 augustss p->size = size;
522 1.1 augustss error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
523 1.1 augustss p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
524 1.1 augustss &p->nsegs, BUS_DMA_NOWAIT);
525 1.1 augustss if (error)
526 1.1 augustss return (error);
527 1.1 augustss
528 1.1 augustss error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
529 1.1 augustss &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
530 1.1 augustss if (error)
531 1.1 augustss goto free;
532 1.1 augustss
533 1.1 augustss error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
534 1.1 augustss 0, BUS_DMA_NOWAIT, &p->map);
535 1.1 augustss if (error)
536 1.1 augustss goto unmap;
537 1.1 augustss
538 1.1 augustss error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
539 1.1 augustss BUS_DMA_NOWAIT);
540 1.1 augustss if (error)
541 1.1 augustss goto destroy;
542 1.1 augustss return (0);
543 1.1 augustss
544 1.1 augustss destroy:
545 1.1 augustss bus_dmamap_destroy(sc->sc_dmatag, p->map);
546 1.1 augustss unmap:
547 1.1 augustss bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
548 1.1 augustss free:
549 1.1 augustss bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
550 1.1 augustss return (error);
551 1.1 augustss }
552 1.1 augustss
553 1.1 augustss int
554 1.1 augustss eap_freemem(sc, p)
555 1.1 augustss struct eap_softc *sc;
556 1.9 mycroft struct eap_dma *p;
557 1.1 augustss {
558 1.1 augustss bus_dmamap_unload(sc->sc_dmatag, p->map);
559 1.1 augustss bus_dmamap_destroy(sc->sc_dmatag, p->map);
560 1.1 augustss bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
561 1.1 augustss bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
562 1.1 augustss return (0);
563 1.1 augustss }
564 1.1 augustss
565 1.1 augustss int
566 1.1 augustss eap_open(addr, flags)
567 1.1 augustss void *addr;
568 1.1 augustss int flags;
569 1.1 augustss {
570 1.1 augustss
571 1.9 mycroft return (0);
572 1.1 augustss }
573 1.1 augustss
574 1.1 augustss /*
575 1.1 augustss * Close function is called at splaudio().
576 1.1 augustss */
577 1.1 augustss void
578 1.1 augustss eap_close(addr)
579 1.1 augustss void *addr;
580 1.1 augustss {
581 1.1 augustss struct eap_softc *sc = addr;
582 1.1 augustss
583 1.9 mycroft eap_halt_output(sc);
584 1.9 mycroft eap_halt_input(sc);
585 1.1 augustss
586 1.9 mycroft sc->sc_pintr = 0;
587 1.9 mycroft sc->sc_rintr = 0;
588 1.1 augustss }
589 1.1 augustss
590 1.1 augustss int
591 1.1 augustss eap_query_encoding(addr, fp)
592 1.1 augustss void *addr;
593 1.1 augustss struct audio_encoding *fp;
594 1.1 augustss {
595 1.1 augustss switch (fp->index) {
596 1.1 augustss case 0:
597 1.1 augustss strcpy(fp->name, AudioEulinear);
598 1.1 augustss fp->encoding = AUDIO_ENCODING_ULINEAR;
599 1.1 augustss fp->precision = 8;
600 1.1 augustss fp->flags = 0;
601 1.1 augustss return (0);
602 1.1 augustss case 1:
603 1.1 augustss strcpy(fp->name, AudioEmulaw);
604 1.1 augustss fp->encoding = AUDIO_ENCODING_ULAW;
605 1.1 augustss fp->precision = 8;
606 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
607 1.1 augustss return (0);
608 1.1 augustss case 2:
609 1.1 augustss strcpy(fp->name, AudioEalaw);
610 1.1 augustss fp->encoding = AUDIO_ENCODING_ALAW;
611 1.1 augustss fp->precision = 8;
612 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
613 1.1 augustss return (0);
614 1.1 augustss case 3:
615 1.1 augustss strcpy(fp->name, AudioEslinear);
616 1.1 augustss fp->encoding = AUDIO_ENCODING_SLINEAR;
617 1.1 augustss fp->precision = 8;
618 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
619 1.1 augustss return (0);
620 1.9 mycroft case 4:
621 1.1 augustss strcpy(fp->name, AudioEslinear_le);
622 1.1 augustss fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
623 1.1 augustss fp->precision = 16;
624 1.1 augustss fp->flags = 0;
625 1.1 augustss return (0);
626 1.1 augustss case 5:
627 1.1 augustss strcpy(fp->name, AudioEulinear_le);
628 1.1 augustss fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
629 1.1 augustss fp->precision = 16;
630 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
631 1.1 augustss return (0);
632 1.1 augustss case 6:
633 1.1 augustss strcpy(fp->name, AudioEslinear_be);
634 1.1 augustss fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
635 1.1 augustss fp->precision = 16;
636 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
637 1.1 augustss return (0);
638 1.1 augustss case 7:
639 1.1 augustss strcpy(fp->name, AudioEulinear_be);
640 1.1 augustss fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
641 1.1 augustss fp->precision = 16;
642 1.1 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
643 1.1 augustss return (0);
644 1.1 augustss default:
645 1.1 augustss return (EINVAL);
646 1.1 augustss }
647 1.1 augustss }
648 1.1 augustss
649 1.1 augustss int
650 1.9 mycroft eap_set_params(addr, setmode, usemode, play, rec)
651 1.1 augustss void *addr;
652 1.1 augustss int setmode, usemode;
653 1.9 mycroft struct audio_params *play, *rec;
654 1.1 augustss {
655 1.1 augustss struct eap_softc *sc = addr;
656 1.9 mycroft struct audio_params *p;
657 1.23 mycroft int mode;
658 1.23 mycroft u_int32_t div;
659 1.9 mycroft
660 1.9 mycroft /*
661 1.9 mycroft * This device only has one clock, so make the sample rates match.
662 1.9 mycroft */
663 1.11 mycroft if (play->sample_rate != rec->sample_rate &&
664 1.11 mycroft usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
665 1.11 mycroft if (setmode == AUMODE_PLAY) {
666 1.9 mycroft rec->sample_rate = play->sample_rate;
667 1.11 mycroft setmode |= AUMODE_RECORD;
668 1.11 mycroft } else if (setmode == AUMODE_RECORD) {
669 1.9 mycroft play->sample_rate = rec->sample_rate;
670 1.11 mycroft setmode |= AUMODE_PLAY;
671 1.11 mycroft } else
672 1.9 mycroft return (EINVAL);
673 1.9 mycroft }
674 1.9 mycroft
675 1.9 mycroft for (mode = AUMODE_RECORD; mode != -1;
676 1.9 mycroft mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
677 1.9 mycroft if ((setmode & mode) == 0)
678 1.9 mycroft continue;
679 1.9 mycroft
680 1.9 mycroft p = mode == AUMODE_PLAY ? play : rec;
681 1.9 mycroft
682 1.9 mycroft if (p->sample_rate < 4000 || p->sample_rate > 50000 ||
683 1.9 mycroft (p->precision != 8 && p->precision != 16) ||
684 1.9 mycroft (p->channels != 1 && p->channels != 2))
685 1.9 mycroft return (EINVAL);
686 1.9 mycroft
687 1.9 mycroft p->factor = 1;
688 1.9 mycroft p->sw_code = 0;
689 1.9 mycroft switch (p->encoding) {
690 1.9 mycroft case AUDIO_ENCODING_SLINEAR_BE:
691 1.9 mycroft if (p->precision == 16)
692 1.9 mycroft p->sw_code = swap_bytes;
693 1.9 mycroft else
694 1.9 mycroft p->sw_code = change_sign8;
695 1.9 mycroft break;
696 1.9 mycroft case AUDIO_ENCODING_SLINEAR_LE:
697 1.9 mycroft if (p->precision != 16)
698 1.9 mycroft p->sw_code = change_sign8;
699 1.9 mycroft break;
700 1.9 mycroft case AUDIO_ENCODING_ULINEAR_BE:
701 1.17 thorpej if (p->precision == 16) {
702 1.9 mycroft if (mode == AUMODE_PLAY)
703 1.9 mycroft p->sw_code = swap_bytes_change_sign16;
704 1.9 mycroft else
705 1.9 mycroft p->sw_code = change_sign16_swap_bytes;
706 1.17 thorpej }
707 1.9 mycroft break;
708 1.9 mycroft case AUDIO_ENCODING_ULINEAR_LE:
709 1.9 mycroft if (p->precision == 16)
710 1.9 mycroft p->sw_code = change_sign16;
711 1.9 mycroft break;
712 1.9 mycroft case AUDIO_ENCODING_ULAW:
713 1.9 mycroft if (mode == AUMODE_PLAY) {
714 1.9 mycroft p->factor = 2;
715 1.9 mycroft p->sw_code = mulaw_to_slinear16;
716 1.9 mycroft } else
717 1.9 mycroft p->sw_code = ulinear8_to_mulaw;
718 1.9 mycroft break;
719 1.9 mycroft case AUDIO_ENCODING_ALAW:
720 1.9 mycroft if (mode == AUMODE_PLAY) {
721 1.9 mycroft p->factor = 2;
722 1.9 mycroft p->sw_code = alaw_to_slinear16;
723 1.9 mycroft } else
724 1.9 mycroft p->sw_code = ulinear8_to_alaw;
725 1.9 mycroft break;
726 1.9 mycroft default:
727 1.9 mycroft return (EINVAL);
728 1.1 augustss }
729 1.9 mycroft }
730 1.1 augustss
731 1.9 mycroft /* Set the speed */
732 1.1 augustss DPRINTFN(2, ("eap_set_params: old ICSC = 0x%08x\n",
733 1.1 augustss EREAD4(sc, EAP_ICSC)));
734 1.1 augustss div = EREAD4(sc, EAP_ICSC) & ~EAP_PCLKBITS;
735 1.9 mycroft /*
736 1.9 mycroft * XXX
737 1.9 mycroft * The -2 isn't documented, but seemed to make the wall time match
738 1.9 mycroft * what I expect. - mycroft
739 1.9 mycroft */
740 1.11 mycroft if (usemode == AUMODE_RECORD)
741 1.11 mycroft div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ / rec->sample_rate - 2);
742 1.11 mycroft else
743 1.11 mycroft div |= EAP_SET_PCLKDIV(EAP_XTAL_FREQ / play->sample_rate - 2);
744 1.1 augustss div |= EAP_CCB_INTRM;
745 1.9 mycroft EWRITE4(sc, EAP_ICSC, div);
746 1.1 augustss DPRINTFN(2, ("eap_set_params: set ICSC = 0x%08x\n", div));
747 1.1 augustss
748 1.9 mycroft return (0);
749 1.1 augustss }
750 1.1 augustss
751 1.1 augustss int
752 1.1 augustss eap_round_blocksize(addr, blk)
753 1.1 augustss void *addr;
754 1.1 augustss int blk;
755 1.1 augustss {
756 1.6 augustss return (blk & -32); /* keep good alignment */
757 1.1 augustss }
758 1.1 augustss
759 1.1 augustss int
760 1.9 mycroft eap_trigger_output(addr, start, end, blksize, intr, arg, param)
761 1.1 augustss void *addr;
762 1.9 mycroft void *start, *end;
763 1.9 mycroft int blksize;
764 1.9 mycroft void (*intr) __P((void *));
765 1.9 mycroft void *arg;
766 1.9 mycroft struct audio_params *param;
767 1.1 augustss {
768 1.1 augustss struct eap_softc *sc = addr;
769 1.1 augustss struct eap_dma *p;
770 1.24 mycroft u_int32_t icsc, sic;
771 1.9 mycroft int sampshift;
772 1.1 augustss
773 1.9 mycroft #ifdef DIAGNOSTIC
774 1.9 mycroft if (sc->sc_prun)
775 1.9 mycroft panic("eap_trigger_output: already running");
776 1.10 mycroft sc->sc_prun = 1;
777 1.9 mycroft #endif
778 1.9 mycroft
779 1.10 mycroft DPRINTFN(1, ("eap_trigger_output: sc=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
780 1.10 mycroft addr, start, end, blksize, intr, arg));
781 1.9 mycroft sc->sc_pintr = intr;
782 1.9 mycroft sc->sc_parg = arg;
783 1.9 mycroft
784 1.24 mycroft icsc = EREAD4(sc, EAP_ICSC);
785 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc & ~EAP_DAC2_EN);
786 1.24 mycroft
787 1.24 mycroft sic = EREAD4(sc, EAP_SIC);
788 1.24 mycroft sic &= ~(EAP_P2_S_EB | EAP_P2_S_MB | EAP_INC_BITS);
789 1.24 mycroft sic |= EAP_SET_P2_ST_INC(0) | EAP_SET_P2_END_INC(param->precision * param->factor / 8);
790 1.9 mycroft sampshift = 0;
791 1.9 mycroft if (param->precision * param->factor == 16) {
792 1.24 mycroft sic |= EAP_P2_S_EB;
793 1.9 mycroft sampshift++;
794 1.9 mycroft }
795 1.9 mycroft if (param->channels == 2) {
796 1.24 mycroft sic |= EAP_P2_S_MB;
797 1.9 mycroft sampshift++;
798 1.1 augustss }
799 1.24 mycroft EWRITE4(sc, EAP_SIC, sic);
800 1.1 augustss
801 1.9 mycroft for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
802 1.1 augustss ;
803 1.1 augustss if (!p) {
804 1.9 mycroft printf("eap_trigger_output: bad addr %p\n", start);
805 1.1 augustss return (EINVAL);
806 1.1 augustss }
807 1.9 mycroft
808 1.9 mycroft DPRINTF(("eap_trigger_output: DAC2_ADDR=0x%x, DAC2_SIZE=0x%x\n",
809 1.20 augustss (int)DMAADDR(p),
810 1.20 augustss EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1)));
811 1.1 augustss EWRITE4(sc, EAP_MEMPAGE, EAP_DAC_PAGE);
812 1.1 augustss EWRITE4(sc, EAP_DAC2_ADDR, DMAADDR(p));
813 1.20 augustss EWRITE4(sc, EAP_DAC2_SIZE,
814 1.20 augustss EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1));
815 1.9 mycroft
816 1.9 mycroft EWRITE2(sc, EAP_DAC2_CSR, (blksize >> sampshift) - 1);
817 1.24 mycroft
818 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc | EAP_DAC2_EN);
819 1.24 mycroft
820 1.24 mycroft DPRINTFN(1, ("eap_trigger_output: set ICSC = 0x%08x\n", icsc));
821 1.9 mycroft
822 1.1 augustss return (0);
823 1.1 augustss }
824 1.1 augustss
825 1.1 augustss int
826 1.9 mycroft eap_trigger_input(addr, start, end, blksize, intr, arg, param)
827 1.1 augustss void *addr;
828 1.9 mycroft void *start, *end;
829 1.9 mycroft int blksize;
830 1.1 augustss void (*intr) __P((void *));
831 1.1 augustss void *arg;
832 1.9 mycroft struct audio_params *param;
833 1.1 augustss {
834 1.1 augustss struct eap_softc *sc = addr;
835 1.9 mycroft struct eap_dma *p;
836 1.24 mycroft u_int32_t icsc, sic;
837 1.9 mycroft int sampshift;
838 1.1 augustss
839 1.9 mycroft #ifdef DIAGNOSTIC
840 1.9 mycroft if (sc->sc_rrun)
841 1.9 mycroft panic("eap_trigger_input: already running");
842 1.10 mycroft sc->sc_rrun = 1;
843 1.1 augustss #endif
844 1.9 mycroft
845 1.10 mycroft DPRINTFN(1, ("eap_trigger_input: sc=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
846 1.10 mycroft addr, start, end, blksize, intr, arg));
847 1.9 mycroft sc->sc_rintr = intr;
848 1.9 mycroft sc->sc_rarg = arg;
849 1.9 mycroft
850 1.24 mycroft icsc = EREAD4(sc, EAP_ICSC);
851 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc & ~EAP_ADC_EN);
852 1.24 mycroft
853 1.24 mycroft sic = EREAD4(sc, EAP_SIC);
854 1.24 mycroft sic &= ~(EAP_R1_S_EB | EAP_R1_S_MB);
855 1.9 mycroft sampshift = 0;
856 1.9 mycroft if (param->precision * param->factor == 16) {
857 1.24 mycroft sic |= EAP_R1_S_EB;
858 1.9 mycroft sampshift++;
859 1.1 augustss }
860 1.9 mycroft if (param->channels == 2) {
861 1.24 mycroft sic |= EAP_R1_S_MB;
862 1.9 mycroft sampshift++;
863 1.9 mycroft }
864 1.24 mycroft EWRITE4(sc, EAP_SIC, sic);
865 1.9 mycroft
866 1.9 mycroft for (p = sc->sc_dmas; p && KERNADDR(p) != start; p = p->next)
867 1.9 mycroft ;
868 1.9 mycroft if (!p) {
869 1.9 mycroft printf("eap_trigger_input: bad addr %p\n", start);
870 1.9 mycroft return (EINVAL);
871 1.9 mycroft }
872 1.9 mycroft
873 1.9 mycroft DPRINTF(("eap_trigger_input: ADC_ADDR=0x%x, ADC_SIZE=0x%x\n",
874 1.20 augustss (int)DMAADDR(p),
875 1.20 augustss EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1)));
876 1.9 mycroft EWRITE4(sc, EAP_MEMPAGE, EAP_ADC_PAGE);
877 1.9 mycroft EWRITE4(sc, EAP_ADC_ADDR, DMAADDR(p));
878 1.20 augustss EWRITE4(sc, EAP_ADC_SIZE,
879 1.20 augustss EAP_SET_SIZE(0, (((char *)end - (char *)start) >> 2) - 1));
880 1.1 augustss
881 1.9 mycroft EWRITE2(sc, EAP_ADC_CSR, (blksize >> sampshift) - 1);
882 1.24 mycroft
883 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc | EAP_ADC_EN);
884 1.24 mycroft
885 1.24 mycroft DPRINTFN(1, ("eap_trigger_input: set ICSC = 0x%08x\n", icsc));
886 1.9 mycroft
887 1.9 mycroft return (0);
888 1.1 augustss }
889 1.1 augustss
890 1.1 augustss int
891 1.9 mycroft eap_halt_output(addr)
892 1.1 augustss void *addr;
893 1.1 augustss {
894 1.1 augustss struct eap_softc *sc = addr;
895 1.24 mycroft u_int32_t icsc;
896 1.1 augustss
897 1.9 mycroft DPRINTF(("eap: eap_halt_output\n"));
898 1.24 mycroft icsc = EREAD4(sc, EAP_ICSC);
899 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc & ~EAP_DAC2_EN);
900 1.9 mycroft #ifdef DIAGNOSTIC
901 1.1 augustss sc->sc_prun = 0;
902 1.9 mycroft #endif
903 1.9 mycroft return (0);
904 1.1 augustss }
905 1.1 augustss
906 1.1 augustss int
907 1.9 mycroft eap_halt_input(addr)
908 1.1 augustss void *addr;
909 1.1 augustss {
910 1.1 augustss struct eap_softc *sc = addr;
911 1.24 mycroft u_int32_t icsc;
912 1.1 augustss
913 1.9 mycroft DPRINTF(("eap: eap_halt_input\n"));
914 1.24 mycroft icsc = EREAD4(sc, EAP_ICSC);
915 1.24 mycroft EWRITE4(sc, EAP_ICSC, icsc & ~EAP_ADC_EN);
916 1.9 mycroft #ifdef DIAGNOSTIC
917 1.1 augustss sc->sc_rrun = 0;
918 1.9 mycroft #endif
919 1.9 mycroft return (0);
920 1.1 augustss }
921 1.1 augustss
922 1.1 augustss int
923 1.1 augustss eap_getdev(addr, retp)
924 1.1 augustss void *addr;
925 1.9 mycroft struct audio_device *retp;
926 1.1 augustss {
927 1.1 augustss *retp = eap_device;
928 1.9 mycroft return (0);
929 1.1 augustss }
930 1.1 augustss
931 1.1 augustss void
932 1.1 augustss eap_set_mixer(sc, a, d)
933 1.1 augustss struct eap_softc *sc;
934 1.9 mycroft int a, d;
935 1.1 augustss {
936 1.1 augustss eap_write_codec(sc, a, d);
937 1.9 mycroft DPRINTFN(1, ("eap_mixer_set_port port 0x%02x = 0x%02x\n", a, d));
938 1.1 augustss }
939 1.1 augustss
940 1.1 augustss
941 1.1 augustss int
942 1.1 augustss eap_mixer_set_port(addr, cp)
943 1.1 augustss void *addr;
944 1.1 augustss mixer_ctrl_t *cp;
945 1.1 augustss {
946 1.1 augustss struct eap_softc *sc = addr;
947 1.1 augustss int lval, rval, l, r, la, ra;
948 1.8 augustss int l1, r1, l2, r2, m, o1, o2;
949 1.1 augustss
950 1.1 augustss if (cp->dev == EAP_RECORD_SOURCE) {
951 1.1 augustss if (cp->type != AUDIO_MIXER_SET)
952 1.1 augustss return (EINVAL);
953 1.1 augustss m = sc->sc_record_source = cp->un.mask;
954 1.1 augustss l1 = l2 = r1 = r2 = 0;
955 1.1 augustss if (m & (1 << EAP_VOICE_VOL))
956 1.8 augustss l2 |= AK_M_VOICE, r2 |= AK_M_VOICE;
957 1.1 augustss if (m & (1 << EAP_FM_VOL))
958 1.1 augustss l1 |= AK_M_FM_L, r1 |= AK_M_FM_R;
959 1.1 augustss if (m & (1 << EAP_CD_VOL))
960 1.1 augustss l1 |= AK_M_CD_L, r1 |= AK_M_CD_R;
961 1.1 augustss if (m & (1 << EAP_LINE_VOL))
962 1.1 augustss l1 |= AK_M_LINE_L, r1 |= AK_M_LINE_R;
963 1.1 augustss if (m & (1 << EAP_AUX_VOL))
964 1.8 augustss l2 |= AK_M2_AUX_L, r2 |= AK_M2_AUX_R;
965 1.1 augustss if (m & (1 << EAP_MIC_VOL))
966 1.1 augustss l2 |= AK_M_TMIC, r2 |= AK_M_TMIC;
967 1.1 augustss eap_set_mixer(sc, AK_IN_MIXER1_L, l1);
968 1.1 augustss eap_set_mixer(sc, AK_IN_MIXER1_R, r1);
969 1.1 augustss eap_set_mixer(sc, AK_IN_MIXER2_L, l2);
970 1.1 augustss eap_set_mixer(sc, AK_IN_MIXER2_R, r2);
971 1.1 augustss return (0);
972 1.1 augustss }
973 1.8 augustss if (cp->dev == EAP_OUTPUT_SELECT) {
974 1.8 augustss if (cp->type != AUDIO_MIXER_SET)
975 1.8 augustss return (EINVAL);
976 1.8 augustss m = sc->sc_output_source = cp->un.mask;
977 1.8 augustss o1 = o2 = 0;
978 1.8 augustss if (m & (1 << EAP_VOICE_VOL))
979 1.8 augustss o2 |= AK_M_VOICE_L | AK_M_VOICE_R;
980 1.8 augustss if (m & (1 << EAP_FM_VOL))
981 1.8 augustss o1 |= AK_M_FM_L | AK_M_FM_R;
982 1.8 augustss if (m & (1 << EAP_CD_VOL))
983 1.8 augustss o1 |= AK_M_CD_L | AK_M_CD_R;
984 1.8 augustss if (m & (1 << EAP_LINE_VOL))
985 1.8 augustss o1 |= AK_M_LINE_L | AK_M_LINE_R;
986 1.8 augustss if (m & (1 << EAP_AUX_VOL))
987 1.8 augustss o2 |= AK_M_AUX_L | AK_M_AUX_R;
988 1.8 augustss if (m & (1 << EAP_MIC_VOL))
989 1.8 augustss o1 |= AK_M_MIC;
990 1.8 augustss eap_set_mixer(sc, AK_OUT_MIXER1, o1);
991 1.8 augustss eap_set_mixer(sc, AK_OUT_MIXER2, o2);
992 1.8 augustss return (0);
993 1.8 augustss }
994 1.12 mycroft if (cp->dev == EAP_MIC_PREAMP) {
995 1.12 mycroft if (cp->type != AUDIO_MIXER_ENUM)
996 1.12 mycroft return (EINVAL);
997 1.12 mycroft if (cp->un.ord != 0 && cp->un.ord != 1)
998 1.12 mycroft return (EINVAL);
999 1.12 mycroft sc->sc_mic_preamp = cp->un.ord;
1000 1.12 mycroft eap_set_mixer(sc, AK_MGAIN, cp->un.ord);
1001 1.12 mycroft return (0);
1002 1.12 mycroft }
1003 1.1 augustss if (cp->type != AUDIO_MIXER_VALUE)
1004 1.1 augustss return (EINVAL);
1005 1.1 augustss if (cp->un.value.num_channels == 1)
1006 1.1 augustss lval = rval = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
1007 1.1 augustss else if (cp->un.value.num_channels == 2) {
1008 1.1 augustss lval = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
1009 1.1 augustss rval = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
1010 1.1 augustss } else
1011 1.1 augustss return (EINVAL);
1012 1.1 augustss ra = -1;
1013 1.1 augustss switch (cp->dev) {
1014 1.1 augustss case EAP_MASTER_VOL:
1015 1.1 augustss l = VOL_TO_ATT5(lval);
1016 1.1 augustss r = VOL_TO_ATT5(rval);
1017 1.1 augustss la = AK_MASTER_L;
1018 1.1 augustss ra = AK_MASTER_R;
1019 1.1 augustss break;
1020 1.1 augustss case EAP_MIC_VOL:
1021 1.1 augustss if (cp->un.value.num_channels != 1)
1022 1.1 augustss return (EINVAL);
1023 1.1 augustss la = AK_MIC;
1024 1.1 augustss goto lr;
1025 1.1 augustss case EAP_VOICE_VOL:
1026 1.1 augustss la = AK_VOICE_L;
1027 1.1 augustss ra = AK_VOICE_R;
1028 1.1 augustss goto lr;
1029 1.1 augustss case EAP_FM_VOL:
1030 1.1 augustss la = AK_FM_L;
1031 1.1 augustss ra = AK_FM_R;
1032 1.1 augustss goto lr;
1033 1.1 augustss case EAP_CD_VOL:
1034 1.1 augustss la = AK_CD_L;
1035 1.1 augustss ra = AK_CD_R;
1036 1.1 augustss goto lr;
1037 1.1 augustss case EAP_LINE_VOL:
1038 1.1 augustss la = AK_LINE_L;
1039 1.1 augustss ra = AK_LINE_R;
1040 1.1 augustss goto lr;
1041 1.1 augustss case EAP_AUX_VOL:
1042 1.1 augustss la = AK_AUX_L;
1043 1.1 augustss ra = AK_AUX_R;
1044 1.1 augustss lr:
1045 1.1 augustss l = VOL_TO_GAIN5(lval);
1046 1.1 augustss r = VOL_TO_GAIN5(rval);
1047 1.1 augustss break;
1048 1.1 augustss default:
1049 1.1 augustss return (EINVAL);
1050 1.1 augustss }
1051 1.1 augustss eap_set_mixer(sc, la, l);
1052 1.1 augustss sc->sc_port[la] = l;
1053 1.1 augustss if (ra >= 0) {
1054 1.1 augustss eap_set_mixer(sc, ra, r);
1055 1.1 augustss sc->sc_port[ra] = r;
1056 1.1 augustss }
1057 1.1 augustss return (0);
1058 1.1 augustss }
1059 1.1 augustss
1060 1.1 augustss int
1061 1.1 augustss eap_mixer_get_port(addr, cp)
1062 1.1 augustss void *addr;
1063 1.1 augustss mixer_ctrl_t *cp;
1064 1.1 augustss {
1065 1.1 augustss struct eap_softc *sc = addr;
1066 1.1 augustss int la, ra, l, r;
1067 1.1 augustss
1068 1.1 augustss switch (cp->dev) {
1069 1.1 augustss case EAP_RECORD_SOURCE:
1070 1.13 mycroft if (cp->type != AUDIO_MIXER_SET)
1071 1.12 mycroft return (EINVAL);
1072 1.1 augustss cp->un.mask = sc->sc_record_source;
1073 1.1 augustss return (0);
1074 1.8 augustss case EAP_OUTPUT_SELECT:
1075 1.13 mycroft if (cp->type != AUDIO_MIXER_SET)
1076 1.12 mycroft return (EINVAL);
1077 1.9 mycroft cp->un.mask = sc->sc_output_source;
1078 1.9 mycroft return (0);
1079 1.12 mycroft case EAP_MIC_PREAMP:
1080 1.13 mycroft if (cp->type != AUDIO_MIXER_ENUM)
1081 1.12 mycroft return (EINVAL);
1082 1.12 mycroft cp->un.ord = sc->sc_mic_preamp;
1083 1.12 mycroft return (0);
1084 1.1 augustss case EAP_MASTER_VOL:
1085 1.2 mycroft l = ATT5_TO_VOL(sc->sc_port[AK_MASTER_L]);
1086 1.2 mycroft r = ATT5_TO_VOL(sc->sc_port[AK_MASTER_R]);
1087 1.1 augustss break;
1088 1.1 augustss case EAP_MIC_VOL:
1089 1.1 augustss if (cp->un.value.num_channels != 1)
1090 1.1 augustss return (EINVAL);
1091 1.1 augustss la = ra = AK_MIC;
1092 1.1 augustss goto lr;
1093 1.1 augustss case EAP_VOICE_VOL:
1094 1.1 augustss la = AK_VOICE_L;
1095 1.1 augustss ra = AK_VOICE_R;
1096 1.1 augustss goto lr;
1097 1.1 augustss case EAP_FM_VOL:
1098 1.1 augustss la = AK_FM_L;
1099 1.1 augustss ra = AK_FM_R;
1100 1.1 augustss goto lr;
1101 1.1 augustss case EAP_CD_VOL:
1102 1.1 augustss la = AK_CD_L;
1103 1.1 augustss ra = AK_CD_R;
1104 1.1 augustss goto lr;
1105 1.1 augustss case EAP_LINE_VOL:
1106 1.1 augustss la = AK_LINE_L;
1107 1.1 augustss ra = AK_LINE_R;
1108 1.1 augustss goto lr;
1109 1.1 augustss case EAP_AUX_VOL:
1110 1.1 augustss la = AK_AUX_L;
1111 1.1 augustss ra = AK_AUX_R;
1112 1.1 augustss lr:
1113 1.1 augustss l = GAIN5_TO_VOL(sc->sc_port[la]);
1114 1.1 augustss r = GAIN5_TO_VOL(sc->sc_port[ra]);
1115 1.1 augustss break;
1116 1.1 augustss default:
1117 1.1 augustss return (EINVAL);
1118 1.1 augustss }
1119 1.1 augustss if (cp->un.value.num_channels == 1)
1120 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
1121 1.1 augustss else if (cp->un.value.num_channels == 2) {
1122 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
1123 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
1124 1.12 mycroft } else
1125 1.12 mycroft return (EINVAL);
1126 1.1 augustss return (0);
1127 1.1 augustss }
1128 1.1 augustss
1129 1.1 augustss int
1130 1.1 augustss eap_query_devinfo(addr, dip)
1131 1.1 augustss void *addr;
1132 1.1 augustss mixer_devinfo_t *dip;
1133 1.1 augustss {
1134 1.1 augustss switch (dip->index) {
1135 1.1 augustss case EAP_MASTER_VOL:
1136 1.1 augustss dip->type = AUDIO_MIXER_VALUE;
1137 1.1 augustss dip->mixer_class = EAP_OUTPUT_CLASS;
1138 1.1 augustss dip->prev = dip->next = AUDIO_MIXER_LAST;
1139 1.1 augustss strcpy(dip->label.name, AudioNmaster);
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_VOICE_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, AudioNdac);
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_FM_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, AudioNfmsynth);
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_CD_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, AudioNcd);
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_LINE_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, AudioNline);
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_AUX_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.1 augustss dip->next = AUDIO_MIXER_LAST;
1184 1.1 augustss strcpy(dip->label.name, AudioNaux);
1185 1.1 augustss dip->un.v.num_channels = 2;
1186 1.1 augustss strcpy(dip->un.v.units.name, AudioNvolume);
1187 1.1 augustss return (0);
1188 1.1 augustss case EAP_MIC_VOL:
1189 1.1 augustss dip->type = AUDIO_MIXER_VALUE;
1190 1.1 augustss dip->mixer_class = EAP_INPUT_CLASS;
1191 1.1 augustss dip->prev = AUDIO_MIXER_LAST;
1192 1.14 mycroft dip->next = EAP_MIC_PREAMP;
1193 1.1 augustss strcpy(dip->label.name, AudioNmicrophone);
1194 1.1 augustss dip->un.v.num_channels = 1;
1195 1.1 augustss strcpy(dip->un.v.units.name, AudioNvolume);
1196 1.1 augustss return (0);
1197 1.1 augustss case EAP_RECORD_SOURCE:
1198 1.1 augustss dip->mixer_class = EAP_RECORD_CLASS;
1199 1.1 augustss dip->prev = dip->next = AUDIO_MIXER_LAST;
1200 1.1 augustss strcpy(dip->label.name, AudioNsource);
1201 1.1 augustss dip->type = AUDIO_MIXER_SET;
1202 1.8 augustss dip->un.s.num_mem = 6;
1203 1.8 augustss strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1204 1.8 augustss dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1205 1.8 augustss strcpy(dip->un.s.member[1].label.name, AudioNcd);
1206 1.8 augustss dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1207 1.8 augustss strcpy(dip->un.s.member[2].label.name, AudioNline);
1208 1.8 augustss dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1209 1.8 augustss strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1210 1.8 augustss dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1211 1.8 augustss strcpy(dip->un.s.member[4].label.name, AudioNaux);
1212 1.8 augustss dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1213 1.8 augustss strcpy(dip->un.s.member[5].label.name, AudioNdac);
1214 1.8 augustss dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1215 1.8 augustss return (0);
1216 1.8 augustss case EAP_OUTPUT_SELECT:
1217 1.8 augustss dip->mixer_class = EAP_OUTPUT_CLASS;
1218 1.8 augustss dip->prev = dip->next = AUDIO_MIXER_LAST;
1219 1.8 augustss strcpy(dip->label.name, AudioNselect);
1220 1.8 augustss dip->type = AUDIO_MIXER_SET;
1221 1.8 augustss dip->un.s.num_mem = 6;
1222 1.1 augustss strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1223 1.1 augustss dip->un.s.member[0].mask = 1 << EAP_MIC_VOL;
1224 1.1 augustss strcpy(dip->un.s.member[1].label.name, AudioNcd);
1225 1.1 augustss dip->un.s.member[1].mask = 1 << EAP_CD_VOL;
1226 1.1 augustss strcpy(dip->un.s.member[2].label.name, AudioNline);
1227 1.1 augustss dip->un.s.member[2].mask = 1 << EAP_LINE_VOL;
1228 1.1 augustss strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1229 1.1 augustss dip->un.s.member[3].mask = 1 << EAP_FM_VOL;
1230 1.1 augustss strcpy(dip->un.s.member[4].label.name, AudioNaux);
1231 1.1 augustss dip->un.s.member[4].mask = 1 << EAP_AUX_VOL;
1232 1.8 augustss strcpy(dip->un.s.member[5].label.name, AudioNdac);
1233 1.8 augustss dip->un.s.member[5].mask = 1 << EAP_VOICE_VOL;
1234 1.12 mycroft return (0);
1235 1.12 mycroft case EAP_MIC_PREAMP:
1236 1.12 mycroft dip->type = AUDIO_MIXER_ENUM;
1237 1.14 mycroft dip->mixer_class = EAP_INPUT_CLASS;
1238 1.14 mycroft dip->prev = EAP_MIC_VOL;
1239 1.14 mycroft dip->next = AUDIO_MIXER_LAST;
1240 1.12 mycroft strcpy(dip->label.name, AudioNpreamp);
1241 1.12 mycroft dip->un.e.num_mem = 2;
1242 1.12 mycroft strcpy(dip->un.e.member[0].label.name, AudioNoff);
1243 1.12 mycroft dip->un.e.member[0].ord = 0;
1244 1.12 mycroft strcpy(dip->un.e.member[1].label.name, AudioNon);
1245 1.12 mycroft dip->un.e.member[1].ord = 1;
1246 1.1 augustss return (0);
1247 1.1 augustss case EAP_OUTPUT_CLASS:
1248 1.1 augustss dip->type = AUDIO_MIXER_CLASS;
1249 1.1 augustss dip->mixer_class = EAP_OUTPUT_CLASS;
1250 1.1 augustss dip->next = dip->prev = AUDIO_MIXER_LAST;
1251 1.1 augustss strcpy(dip->label.name, AudioCoutputs);
1252 1.1 augustss return (0);
1253 1.1 augustss case EAP_RECORD_CLASS:
1254 1.1 augustss dip->type = AUDIO_MIXER_CLASS;
1255 1.1 augustss dip->mixer_class = EAP_RECORD_CLASS;
1256 1.1 augustss dip->next = dip->prev = AUDIO_MIXER_LAST;
1257 1.1 augustss strcpy(dip->label.name, AudioCrecord);
1258 1.1 augustss return (0);
1259 1.1 augustss case EAP_INPUT_CLASS:
1260 1.1 augustss dip->type = AUDIO_MIXER_CLASS;
1261 1.1 augustss dip->mixer_class = EAP_INPUT_CLASS;
1262 1.1 augustss dip->next = dip->prev = AUDIO_MIXER_LAST;
1263 1.1 augustss strcpy(dip->label.name, AudioCinputs);
1264 1.1 augustss return (0);
1265 1.1 augustss }
1266 1.1 augustss return (ENXIO);
1267 1.1 augustss }
1268 1.1 augustss
1269 1.1 augustss void *
1270 1.21 mycroft eap_malloc(addr, direction, size, pool, flags)
1271 1.1 augustss void *addr;
1272 1.21 mycroft int direction;
1273 1.21 mycroft size_t size;
1274 1.21 mycroft int pool, flags;
1275 1.1 augustss {
1276 1.1 augustss struct eap_softc *sc = addr;
1277 1.9 mycroft struct eap_dma *p;
1278 1.9 mycroft int error;
1279 1.1 augustss
1280 1.9 mycroft p = malloc(sizeof(*p), pool, flags);
1281 1.9 mycroft if (!p)
1282 1.9 mycroft return (0);
1283 1.9 mycroft error = eap_allocmem(sc, size, 16, p);
1284 1.9 mycroft if (error) {
1285 1.9 mycroft free(p, pool);
1286 1.9 mycroft return (0);
1287 1.9 mycroft }
1288 1.9 mycroft p->next = sc->sc_dmas;
1289 1.9 mycroft sc->sc_dmas = p;
1290 1.1 augustss return (KERNADDR(p));
1291 1.1 augustss }
1292 1.1 augustss
1293 1.1 augustss void
1294 1.1 augustss eap_free(addr, ptr, pool)
1295 1.1 augustss void *addr;
1296 1.1 augustss void *ptr;
1297 1.1 augustss int pool;
1298 1.1 augustss {
1299 1.1 augustss struct eap_softc *sc = addr;
1300 1.26 kleink struct eap_dma **pp, *p;
1301 1.1 augustss
1302 1.26 kleink for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) {
1303 1.26 kleink if (KERNADDR(p) == ptr) {
1304 1.26 kleink eap_freemem(sc, p);
1305 1.26 kleink *pp = p->next;
1306 1.26 kleink free(p, pool);
1307 1.9 mycroft return;
1308 1.9 mycroft }
1309 1.9 mycroft }
1310 1.1 augustss }
1311 1.1 augustss
1312 1.21 mycroft size_t
1313 1.21 mycroft eap_round_buffersize(addr, direction, size)
1314 1.1 augustss void *addr;
1315 1.21 mycroft int direction;
1316 1.21 mycroft size_t size;
1317 1.1 augustss {
1318 1.1 augustss return (size);
1319 1.1 augustss }
1320 1.1 augustss
1321 1.1 augustss int
1322 1.1 augustss eap_mappage(addr, mem, off, prot)
1323 1.1 augustss void *addr;
1324 1.9 mycroft void *mem;
1325 1.9 mycroft int off;
1326 1.1 augustss int prot;
1327 1.1 augustss {
1328 1.1 augustss struct eap_softc *sc = addr;
1329 1.9 mycroft struct eap_dma *p;
1330 1.1 augustss
1331 1.18 mrg if (off < 0)
1332 1.18 mrg return (-1);
1333 1.9 mycroft for (p = sc->sc_dmas; p && KERNADDR(p) != mem; p = p->next)
1334 1.1 augustss ;
1335 1.1 augustss if (!p)
1336 1.1 augustss return (-1);
1337 1.1 augustss return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
1338 1.1 augustss off, prot, BUS_DMA_WAITOK));
1339 1.1 augustss }
1340 1.1 augustss
1341 1.1 augustss int
1342 1.1 augustss eap_get_props(addr)
1343 1.1 augustss void *addr;
1344 1.1 augustss {
1345 1.9 mycroft return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX);
1346 1.1 augustss }
1347