cmpci.c revision 1.4.2.2 1 1.4.2.2 bouyer /* $NetBSD: cmpci.c,v 1.4.2.2 2000/11/20 11:42:15 bouyer Exp $ */
2 1.4.2.2 bouyer
3 1.4.2.2 bouyer /*
4 1.4.2.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.4.2.2 bouyer * All rights reserved.
6 1.4.2.2 bouyer *
7 1.4.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.2 bouyer * by Takuya SHIOZAKI <AoiMoe (at) imou.to> .
9 1.4.2.2 bouyer *
10 1.4.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.4.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.4.2.2 bouyer * are met:
13 1.4.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.4.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.4.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.4.2.2 bouyer *
19 1.4.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 1.4.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.4.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.4.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 1.4.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.4.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.4.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.4.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.4.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.4.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.4.2.2 bouyer * SUCH DAMAGE.
30 1.4.2.2 bouyer *
31 1.4.2.2 bouyer */
32 1.4.2.2 bouyer
33 1.4.2.2 bouyer /*
34 1.4.2.2 bouyer * C-Media CMI8x38 Audio Chip Support.
35 1.4.2.2 bouyer *
36 1.4.2.2 bouyer * TODO:
37 1.4.2.2 bouyer * - Legacy MPU, OPL and Joystick support (but, I have no interest...)
38 1.4.2.2 bouyer * - SPDIF support.
39 1.4.2.2 bouyer *
40 1.4.2.2 bouyer * ACKNOWLEDGEMENT:
41 1.4.2.2 bouyer * - Lennart Augustsson : He touched up this code.
42 1.4.2.2 bouyer *
43 1.4.2.2 bouyer */
44 1.4.2.2 bouyer
45 1.4.2.2 bouyer #undef CMPCI_SPDIF_SUPPORT /* XXX: not working */
46 1.4.2.2 bouyer
47 1.4.2.2 bouyer #if defined(AUDIO_DEBUG) || defined(DEBUG)
48 1.4.2.2 bouyer #define DPRINTF(x) printf x
49 1.4.2.2 bouyer #else
50 1.4.2.2 bouyer #define DPRINTF(x)
51 1.4.2.2 bouyer #endif
52 1.4.2.2 bouyer
53 1.4.2.2 bouyer #include <sys/param.h>
54 1.4.2.2 bouyer #include <sys/systm.h>
55 1.4.2.2 bouyer #include <sys/kernel.h>
56 1.4.2.2 bouyer #include <sys/malloc.h>
57 1.4.2.2 bouyer #include <sys/device.h>
58 1.4.2.2 bouyer #include <sys/proc.h>
59 1.4.2.2 bouyer
60 1.4.2.2 bouyer #include <dev/pci/pcidevs.h>
61 1.4.2.2 bouyer #include <dev/pci/pcivar.h>
62 1.4.2.2 bouyer
63 1.4.2.2 bouyer #include <sys/audioio.h>
64 1.4.2.2 bouyer #include <dev/audio_if.h>
65 1.4.2.2 bouyer #include <dev/midi_if.h>
66 1.4.2.2 bouyer
67 1.4.2.2 bouyer #include <dev/mulaw.h>
68 1.4.2.2 bouyer #include <dev/auconv.h>
69 1.4.2.2 bouyer #include <dev/pci/cmpcireg.h>
70 1.4.2.2 bouyer #include <dev/pci/cmpcivar.h>
71 1.4.2.2 bouyer
72 1.4.2.2 bouyer #include <dev/ic/mpuvar.h>
73 1.4.2.2 bouyer #include <machine/bus.h>
74 1.4.2.2 bouyer #include <machine/intr.h>
75 1.4.2.2 bouyer
76 1.4.2.2 bouyer /*
77 1.4.2.2 bouyer * Low-level HW interface
78 1.4.2.2 bouyer */
79 1.4.2.2 bouyer static __inline uint8_t cmpci_mixerreg_read __P((struct cmpci_softc *,
80 1.4.2.2 bouyer uint8_t));
81 1.4.2.2 bouyer static __inline void cmpci_mixerreg_write __P((struct cmpci_softc *,
82 1.4.2.2 bouyer uint8_t, uint8_t));
83 1.4.2.2 bouyer static __inline void cmpci_reg_partial_write_4 __P((struct cmpci_softc *,
84 1.4.2.2 bouyer int, int,
85 1.4.2.2 bouyer uint32_t, uint32_t));
86 1.4.2.2 bouyer static __inline void cmpci_reg_set_4 __P((struct cmpci_softc *,
87 1.4.2.2 bouyer int, uint32_t));
88 1.4.2.2 bouyer static __inline void cmpci_reg_clear_4 __P((struct cmpci_softc *,
89 1.4.2.2 bouyer int, uint32_t));
90 1.4.2.2 bouyer static int cmpci_rate_to_index __P((int));
91 1.4.2.2 bouyer static __inline int cmpci_index_to_rate __P((int));
92 1.4.2.2 bouyer static __inline int cmpci_index_to_divider __P((int));
93 1.4.2.2 bouyer
94 1.4.2.2 bouyer static int cmpci_adjust __P((int, int));
95 1.4.2.2 bouyer static void cmpci_set_mixer_gain __P((struct cmpci_softc *, int));
96 1.4.2.2 bouyer static int cmpci_set_in_ports __P((struct cmpci_softc *, int));
97 1.4.2.2 bouyer
98 1.4.2.2 bouyer
99 1.4.2.2 bouyer /*
100 1.4.2.2 bouyer * autoconf interface
101 1.4.2.2 bouyer */
102 1.4.2.2 bouyer static int cmpci_match __P((struct device *, struct cfdata *, void *));
103 1.4.2.2 bouyer static void cmpci_attach __P((struct device *, struct device *, void *));
104 1.4.2.2 bouyer
105 1.4.2.2 bouyer struct cfattach cmpci_ca = {
106 1.4.2.2 bouyer sizeof (struct cmpci_softc), cmpci_match, cmpci_attach
107 1.4.2.2 bouyer };
108 1.4.2.2 bouyer
109 1.4.2.2 bouyer /* interrupt */
110 1.4.2.2 bouyer static int cmpci_intr __P((void *));
111 1.4.2.2 bouyer
112 1.4.2.2 bouyer
113 1.4.2.2 bouyer /*
114 1.4.2.2 bouyer * DMA stuffs
115 1.4.2.2 bouyer */
116 1.4.2.2 bouyer static int cmpci_alloc_dmamem __P((struct cmpci_softc *,
117 1.4.2.2 bouyer size_t, int, int, caddr_t *));
118 1.4.2.2 bouyer static int cmpci_free_dmamem __P((struct cmpci_softc *, caddr_t, int));
119 1.4.2.2 bouyer static struct cmpci_dmanode * cmpci_find_dmamem __P((struct cmpci_softc *,
120 1.4.2.2 bouyer caddr_t));
121 1.4.2.2 bouyer
122 1.4.2.2 bouyer
123 1.4.2.2 bouyer /*
124 1.4.2.2 bouyer * interface to machine independent layer
125 1.4.2.2 bouyer */
126 1.4.2.2 bouyer static int cmpci_open __P((void *, int));
127 1.4.2.2 bouyer static void cmpci_close __P((void *));
128 1.4.2.2 bouyer static int cmpci_query_encoding __P((void *, struct audio_encoding *));
129 1.4.2.2 bouyer static int cmpci_set_params __P((void *, int, int,
130 1.4.2.2 bouyer struct audio_params *,
131 1.4.2.2 bouyer struct audio_params *));
132 1.4.2.2 bouyer static int cmpci_round_blocksize __P((void *, int));
133 1.4.2.2 bouyer static int cmpci_halt_output __P((void *));
134 1.4.2.2 bouyer static int cmpci_halt_input __P((void *));
135 1.4.2.2 bouyer static int cmpci_getdev __P((void *, struct audio_device *));
136 1.4.2.2 bouyer static int cmpci_set_port __P((void *, mixer_ctrl_t *));
137 1.4.2.2 bouyer static int cmpci_get_port __P((void *, mixer_ctrl_t *));
138 1.4.2.2 bouyer static int cmpci_query_devinfo __P((void *, mixer_devinfo_t *));
139 1.4.2.2 bouyer static void *cmpci_allocm __P((void *, int, size_t, int, int));
140 1.4.2.2 bouyer static void cmpci_freem __P((void *, void *, int));
141 1.4.2.2 bouyer static size_t cmpci_round_buffersize __P((void *, int, size_t));
142 1.4.2.2 bouyer static paddr_t cmpci_mappage __P((void *, void *, off_t, int));
143 1.4.2.2 bouyer static int cmpci_get_props __P((void *));
144 1.4.2.2 bouyer static int cmpci_trigger_output __P((void *, void *, void *, int,
145 1.4.2.2 bouyer void (*)(void *), void *,
146 1.4.2.2 bouyer struct audio_params *));
147 1.4.2.2 bouyer static int cmpci_trigger_input __P((void *, void *, void *, int,
148 1.4.2.2 bouyer void (*)(void *), void *,
149 1.4.2.2 bouyer struct audio_params *));
150 1.4.2.2 bouyer
151 1.4.2.2 bouyer static struct audio_hw_if cmpci_hw_if = {
152 1.4.2.2 bouyer cmpci_open, /* open */
153 1.4.2.2 bouyer cmpci_close, /* close */
154 1.4.2.2 bouyer NULL, /* drain */
155 1.4.2.2 bouyer cmpci_query_encoding, /* query_encoding */
156 1.4.2.2 bouyer cmpci_set_params, /* set_params */
157 1.4.2.2 bouyer cmpci_round_blocksize, /* round_blocksize */
158 1.4.2.2 bouyer NULL, /* commit_settings */
159 1.4.2.2 bouyer NULL, /* init_output */
160 1.4.2.2 bouyer NULL, /* init_input */
161 1.4.2.2 bouyer NULL, /* start_output */
162 1.4.2.2 bouyer NULL, /* start_input */
163 1.4.2.2 bouyer cmpci_halt_output, /* halt_output */
164 1.4.2.2 bouyer cmpci_halt_input, /* halt_input */
165 1.4.2.2 bouyer NULL, /* speaker_ctl */
166 1.4.2.2 bouyer cmpci_getdev, /* getdev */
167 1.4.2.2 bouyer NULL, /* setfd */
168 1.4.2.2 bouyer cmpci_set_port, /* set_port */
169 1.4.2.2 bouyer cmpci_get_port, /* get_port */
170 1.4.2.2 bouyer cmpci_query_devinfo, /* query_devinfo */
171 1.4.2.2 bouyer cmpci_allocm, /* allocm */
172 1.4.2.2 bouyer cmpci_freem, /* freem */
173 1.4.2.2 bouyer cmpci_round_buffersize,/* round_buffersize */
174 1.4.2.2 bouyer cmpci_mappage, /* mappage */
175 1.4.2.2 bouyer cmpci_get_props, /* get_props */
176 1.4.2.2 bouyer cmpci_trigger_output, /* trigger_output */
177 1.4.2.2 bouyer cmpci_trigger_input /* trigger_input */
178 1.4.2.2 bouyer };
179 1.4.2.2 bouyer
180 1.4.2.2 bouyer
181 1.4.2.2 bouyer /*
182 1.4.2.2 bouyer * Low-level HW interface
183 1.4.2.2 bouyer */
184 1.4.2.2 bouyer
185 1.4.2.2 bouyer /* mixer register read/write */
186 1.4.2.2 bouyer static __inline uint8_t
187 1.4.2.2 bouyer cmpci_mixerreg_read(sc, no)
188 1.4.2.2 bouyer struct cmpci_softc *sc;
189 1.4.2.2 bouyer uint8_t no;
190 1.4.2.2 bouyer {
191 1.4.2.2 bouyer uint8_t ret;
192 1.4.2.2 bouyer
193 1.4.2.2 bouyer bus_space_write_1(sc->sc_iot, sc->sc_ioh, CMPCI_REG_SBADDR, no);
194 1.4.2.2 bouyer delay(10);
195 1.4.2.2 bouyer ret = bus_space_read_1(sc->sc_iot, sc->sc_ioh, CMPCI_REG_SBDATA);
196 1.4.2.2 bouyer delay(10);
197 1.4.2.2 bouyer return ret;
198 1.4.2.2 bouyer }
199 1.4.2.2 bouyer
200 1.4.2.2 bouyer static __inline void
201 1.4.2.2 bouyer cmpci_mixerreg_write(sc, no, val)
202 1.4.2.2 bouyer struct cmpci_softc *sc;
203 1.4.2.2 bouyer uint8_t no, val;
204 1.4.2.2 bouyer {
205 1.4.2.2 bouyer bus_space_write_1(sc->sc_iot, sc->sc_ioh, CMPCI_REG_SBADDR, no);
206 1.4.2.2 bouyer delay(10);
207 1.4.2.2 bouyer bus_space_write_1(sc->sc_iot, sc->sc_ioh, CMPCI_REG_SBDATA, val);
208 1.4.2.2 bouyer delay(10);
209 1.4.2.2 bouyer }
210 1.4.2.2 bouyer
211 1.4.2.2 bouyer
212 1.4.2.2 bouyer /* register partial write */
213 1.4.2.2 bouyer static __inline void
214 1.4.2.2 bouyer cmpci_reg_partial_write_4(sc, no, shift, mask, val)
215 1.4.2.2 bouyer struct cmpci_softc *sc;
216 1.4.2.2 bouyer int no, shift;
217 1.4.2.2 bouyer uint32_t mask, val;
218 1.4.2.2 bouyer {
219 1.4.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, no,
220 1.4.2.2 bouyer (val<<shift) |
221 1.4.2.2 bouyer (bus_space_read_4(sc->sc_iot, sc->sc_ioh, no) & ~(mask<<shift)));
222 1.4.2.2 bouyer delay(10);
223 1.4.2.2 bouyer }
224 1.4.2.2 bouyer
225 1.4.2.2 bouyer /* register set/clear bit */
226 1.4.2.2 bouyer static __inline void
227 1.4.2.2 bouyer cmpci_reg_set_4(sc, no, mask)
228 1.4.2.2 bouyer struct cmpci_softc *sc;
229 1.4.2.2 bouyer int no;
230 1.4.2.2 bouyer uint32_t mask;
231 1.4.2.2 bouyer {
232 1.4.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, no,
233 1.4.2.2 bouyer (bus_space_read_4(sc->sc_iot, sc->sc_ioh, no) | mask));
234 1.4.2.2 bouyer delay(10);
235 1.4.2.2 bouyer }
236 1.4.2.2 bouyer
237 1.4.2.2 bouyer static __inline void
238 1.4.2.2 bouyer cmpci_reg_clear_4(sc, no, mask)
239 1.4.2.2 bouyer struct cmpci_softc *sc;
240 1.4.2.2 bouyer int no;
241 1.4.2.2 bouyer uint32_t mask;
242 1.4.2.2 bouyer {
243 1.4.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, no,
244 1.4.2.2 bouyer (bus_space_read_4(sc->sc_iot, sc->sc_ioh, no) & ~mask));
245 1.4.2.2 bouyer delay(10);
246 1.4.2.2 bouyer }
247 1.4.2.2 bouyer
248 1.4.2.2 bouyer
249 1.4.2.2 bouyer /* rate */
250 1.4.2.2 bouyer static struct {
251 1.4.2.2 bouyer int rate;
252 1.4.2.2 bouyer int divider;
253 1.4.2.2 bouyer } cmpci_rate_table[CMPCI_REG_NUMRATE] = {
254 1.4.2.2 bouyer #define _RATE(n) { n, CMPCI_REG_RATE_ ## n }
255 1.4.2.2 bouyer _RATE(5512),
256 1.4.2.2 bouyer _RATE(8000),
257 1.4.2.2 bouyer _RATE(11025),
258 1.4.2.2 bouyer _RATE(16000),
259 1.4.2.2 bouyer _RATE(22050),
260 1.4.2.2 bouyer _RATE(32000),
261 1.4.2.2 bouyer _RATE(44100),
262 1.4.2.2 bouyer _RATE(48000)
263 1.4.2.2 bouyer #undef _RATE
264 1.4.2.2 bouyer };
265 1.4.2.2 bouyer
266 1.4.2.2 bouyer static int
267 1.4.2.2 bouyer cmpci_rate_to_index(rate)
268 1.4.2.2 bouyer int rate;
269 1.4.2.2 bouyer {
270 1.4.2.2 bouyer int i;
271 1.4.2.2 bouyer
272 1.4.2.2 bouyer for (i = 0; i < CMPCI_REG_NUMRATE - 2; i++)
273 1.4.2.2 bouyer if (rate <=
274 1.4.2.2 bouyer (cmpci_rate_table[i].rate+cmpci_rate_table[i+1].rate) / 2)
275 1.4.2.2 bouyer return i;
276 1.4.2.2 bouyer return i; /* 48000 */
277 1.4.2.2 bouyer }
278 1.4.2.2 bouyer
279 1.4.2.2 bouyer static __inline int
280 1.4.2.2 bouyer cmpci_index_to_rate(index)
281 1.4.2.2 bouyer int index;
282 1.4.2.2 bouyer {
283 1.4.2.2 bouyer return cmpci_rate_table[index].rate;
284 1.4.2.2 bouyer }
285 1.4.2.2 bouyer
286 1.4.2.2 bouyer static __inline int
287 1.4.2.2 bouyer cmpci_index_to_divider(index)
288 1.4.2.2 bouyer int index;
289 1.4.2.2 bouyer {
290 1.4.2.2 bouyer return cmpci_rate_table[index].divider;
291 1.4.2.2 bouyer }
292 1.4.2.2 bouyer
293 1.4.2.2 bouyer
294 1.4.2.2 bouyer /*
295 1.4.2.2 bouyer * interface to configure the device.
296 1.4.2.2 bouyer */
297 1.4.2.2 bouyer
298 1.4.2.2 bouyer static int
299 1.4.2.2 bouyer cmpci_match(parent, match, aux)
300 1.4.2.2 bouyer struct device *parent;
301 1.4.2.2 bouyer struct cfdata *match;
302 1.4.2.2 bouyer void *aux;
303 1.4.2.2 bouyer {
304 1.4.2.2 bouyer struct pci_attach_args *pa = (struct pci_attach_args *)aux;
305 1.4.2.2 bouyer
306 1.4.2.2 bouyer if ( PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CMEDIA &&
307 1.4.2.2 bouyer (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CMEDIA_CMI8338A ||
308 1.4.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CMEDIA_CMI8338B ||
309 1.4.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CMEDIA_CMI8738) )
310 1.4.2.2 bouyer return 1;
311 1.4.2.2 bouyer
312 1.4.2.2 bouyer return 0;
313 1.4.2.2 bouyer }
314 1.4.2.2 bouyer
315 1.4.2.2 bouyer static void
316 1.4.2.2 bouyer cmpci_attach(parent, self, aux)
317 1.4.2.2 bouyer struct device *parent, *self;
318 1.4.2.2 bouyer void *aux;
319 1.4.2.2 bouyer {
320 1.4.2.2 bouyer struct cmpci_softc *sc = (struct cmpci_softc *)self;
321 1.4.2.2 bouyer struct pci_attach_args *pa = (struct pci_attach_args *)aux;
322 1.4.2.2 bouyer pci_intr_handle_t ih;
323 1.4.2.2 bouyer char const *strintr;
324 1.4.2.2 bouyer int i, v;
325 1.4.2.2 bouyer
326 1.4.2.2 bouyer sc->sc_revision = PCI_REVISION(pa->pa_class);
327 1.4.2.2 bouyer sc->sc_model = PCI_PRODUCT(pa->pa_id);
328 1.4.2.2 bouyer switch (sc->sc_model) {
329 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8338A:
330 1.4.2.2 bouyer printf(": CMI8338A PCI Audio Device\n");
331 1.4.2.2 bouyer break;
332 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8338B:
333 1.4.2.2 bouyer printf(": CMI8338B PCI Audio Device\n");
334 1.4.2.2 bouyer break;
335 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8738:
336 1.4.2.2 bouyer printf(": CMI8738 PCI Audio Device\n");
337 1.4.2.2 bouyer break;
338 1.4.2.2 bouyer }
339 1.4.2.2 bouyer
340 1.4.2.2 bouyer /* map I/O space */
341 1.4.2.2 bouyer if (pci_mapreg_map(pa, CMPCI_PCI_IOBASEREG, PCI_MAPREG_TYPE_IO, 0,
342 1.4.2.2 bouyer &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
343 1.4.2.2 bouyer printf("%s: failed to map I/O space\n", sc->sc_dev.dv_xname);
344 1.4.2.2 bouyer return;
345 1.4.2.2 bouyer }
346 1.4.2.2 bouyer
347 1.4.2.2 bouyer /* interrupt */
348 1.4.2.2 bouyer if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
349 1.4.2.2 bouyer pa->pa_intrline, &ih)) {
350 1.4.2.2 bouyer printf("%s: failed to map interrupt\n", sc->sc_dev.dv_xname);
351 1.4.2.2 bouyer return;
352 1.4.2.2 bouyer }
353 1.4.2.2 bouyer strintr = pci_intr_string(pa->pa_pc, ih);
354 1.4.2.2 bouyer sc->sc_ih=pci_intr_establish(pa->pa_pc, ih, IPL_AUDIO, cmpci_intr, sc);
355 1.4.2.2 bouyer if (sc->sc_ih == NULL) {
356 1.4.2.2 bouyer printf("%s: failed to establish interrupt",
357 1.4.2.2 bouyer sc->sc_dev.dv_xname);
358 1.4.2.2 bouyer if (strintr != NULL)
359 1.4.2.2 bouyer printf(" at %s", strintr);
360 1.4.2.2 bouyer printf("\n");
361 1.4.2.2 bouyer return;
362 1.4.2.2 bouyer }
363 1.4.2.2 bouyer printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, strintr);
364 1.4.2.2 bouyer
365 1.4.2.2 bouyer sc->sc_dmat = pa->pa_dmat;
366 1.4.2.2 bouyer
367 1.4.2.2 bouyer audio_attach_mi(&cmpci_hw_if, sc, &sc->sc_dev);
368 1.4.2.2 bouyer
369 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_RESET, 0);
370 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_L, 0);
371 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_R, 0);
372 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_OUTMIX,
373 1.4.2.2 bouyer CMPCI_SB16_SW_CD|CMPCI_SB16_SW_MIC | CMPCI_SB16_SW_LINE);
374 1.4.2.2 bouyer for (i = 0; i < CMPCI_NDEVS; i++) {
375 1.4.2.2 bouyer switch(i) {
376 1.4.2.2 bouyer case CMPCI_MIC_VOL:
377 1.4.2.2 bouyer case CMPCI_LINE_IN_VOL:
378 1.4.2.2 bouyer v = 0;
379 1.4.2.2 bouyer break;
380 1.4.2.2 bouyer case CMPCI_BASS:
381 1.4.2.2 bouyer case CMPCI_TREBLE:
382 1.4.2.2 bouyer v = CMPCI_ADJUST_GAIN(sc, AUDIO_MAX_GAIN / 2);
383 1.4.2.2 bouyer break;
384 1.4.2.2 bouyer case CMPCI_CD_IN_MUTE:
385 1.4.2.2 bouyer case CMPCI_MIC_IN_MUTE:
386 1.4.2.2 bouyer case CMPCI_LINE_IN_MUTE:
387 1.4.2.2 bouyer case CMPCI_FM_IN_MUTE:
388 1.4.2.2 bouyer case CMPCI_CD_SWAP:
389 1.4.2.2 bouyer case CMPCI_MIC_SWAP:
390 1.4.2.2 bouyer case CMPCI_LINE_SWAP:
391 1.4.2.2 bouyer case CMPCI_FM_SWAP:
392 1.4.2.2 bouyer v = 0;
393 1.4.2.2 bouyer break;
394 1.4.2.2 bouyer case CMPCI_CD_OUT_MUTE:
395 1.4.2.2 bouyer case CMPCI_MIC_OUT_MUTE:
396 1.4.2.2 bouyer case CMPCI_LINE_OUT_MUTE:
397 1.4.2.2 bouyer v = 1;
398 1.4.2.2 bouyer break;
399 1.4.2.2 bouyer default:
400 1.4.2.2 bouyer v = CMPCI_ADJUST_GAIN(sc, AUDIO_MAX_GAIN / 2);
401 1.4.2.2 bouyer }
402 1.4.2.2 bouyer sc->gain[i][CMPCI_LEFT] = sc->gain[i][CMPCI_RIGHT] = v;
403 1.4.2.2 bouyer cmpci_set_mixer_gain(sc, i);
404 1.4.2.2 bouyer }
405 1.4.2.2 bouyer }
406 1.4.2.2 bouyer
407 1.4.2.2 bouyer
408 1.4.2.2 bouyer static int
409 1.4.2.2 bouyer cmpci_intr(handle)
410 1.4.2.2 bouyer void *handle;
411 1.4.2.2 bouyer {
412 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
413 1.4.2.2 bouyer uint32_t intrstat;
414 1.4.2.2 bouyer
415 1.4.2.2 bouyer intrstat = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
416 1.4.2.2 bouyer CMPCI_REG_INTR_STATUS);
417 1.4.2.2 bouyer delay(10);
418 1.4.2.2 bouyer
419 1.4.2.2 bouyer if (!(intrstat & CMPCI_REG_ANY_INTR))
420 1.4.2.2 bouyer return 0;
421 1.4.2.2 bouyer
422 1.4.2.2 bouyer /* disable and reset intr */
423 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH0_INTR)
424 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_INTR_CTRL,
425 1.4.2.2 bouyer CMPCI_REG_CH0_INTR_ENABLE);
426 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH1_INTR)
427 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_INTR_CTRL,
428 1.4.2.2 bouyer CMPCI_REG_CH1_INTR_ENABLE);
429 1.4.2.2 bouyer
430 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH0_INTR) {
431 1.4.2.2 bouyer if (sc->sc_play.intr != NULL)
432 1.4.2.2 bouyer (*sc->sc_play.intr)(sc->sc_play.intr_arg);
433 1.4.2.2 bouyer }
434 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH1_INTR) {
435 1.4.2.2 bouyer if (sc->sc_rec.intr != NULL)
436 1.4.2.2 bouyer (*sc->sc_rec.intr)(sc->sc_rec.intr_arg);
437 1.4.2.2 bouyer }
438 1.4.2.2 bouyer
439 1.4.2.2 bouyer /* enable intr */
440 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH0_INTR)
441 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_INTR_CTRL,
442 1.4.2.2 bouyer CMPCI_REG_CH0_INTR_ENABLE);
443 1.4.2.2 bouyer if (intrstat & CMPCI_REG_CH1_INTR)
444 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_INTR_CTRL,
445 1.4.2.2 bouyer CMPCI_REG_CH1_INTR_ENABLE);
446 1.4.2.2 bouyer
447 1.4.2.2 bouyer return 0;
448 1.4.2.2 bouyer }
449 1.4.2.2 bouyer
450 1.4.2.2 bouyer
451 1.4.2.2 bouyer /* open/close */
452 1.4.2.2 bouyer static int
453 1.4.2.2 bouyer cmpci_open(handle, flags)
454 1.4.2.2 bouyer void *handle;
455 1.4.2.2 bouyer int flags;
456 1.4.2.2 bouyer {
457 1.4.2.2 bouyer #if 0
458 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
459 1.4.2.2 bouyer #endif
460 1.4.2.2 bouyer
461 1.4.2.2 bouyer return 0;
462 1.4.2.2 bouyer }
463 1.4.2.2 bouyer
464 1.4.2.2 bouyer static void
465 1.4.2.2 bouyer cmpci_close(handle)
466 1.4.2.2 bouyer void *handle;
467 1.4.2.2 bouyer {
468 1.4.2.2 bouyer }
469 1.4.2.2 bouyer
470 1.4.2.2 bouyer static int
471 1.4.2.2 bouyer cmpci_query_encoding(handle, fp)
472 1.4.2.2 bouyer void *handle;
473 1.4.2.2 bouyer struct audio_encoding *fp;
474 1.4.2.2 bouyer {
475 1.4.2.2 bouyer #if 0
476 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
477 1.4.2.2 bouyer #endif
478 1.4.2.2 bouyer
479 1.4.2.2 bouyer switch (fp->index) {
480 1.4.2.2 bouyer case 0:
481 1.4.2.2 bouyer strcpy(fp->name, AudioEulinear);
482 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_ULINEAR;
483 1.4.2.2 bouyer fp->precision = 8;
484 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
485 1.4.2.2 bouyer break;
486 1.4.2.2 bouyer case 1:
487 1.4.2.2 bouyer strcpy(fp->name, AudioEmulaw);
488 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_ULAW;
489 1.4.2.2 bouyer fp->precision = 8;
490 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
491 1.4.2.2 bouyer break;
492 1.4.2.2 bouyer case 2:
493 1.4.2.2 bouyer strcpy(fp->name, AudioEalaw);
494 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_ALAW;
495 1.4.2.2 bouyer fp->precision = 8;
496 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
497 1.4.2.2 bouyer break;
498 1.4.2.2 bouyer case 3:
499 1.4.2.2 bouyer strcpy(fp->name, AudioEslinear);
500 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_SLINEAR;
501 1.4.2.2 bouyer fp->precision = 8;
502 1.4.2.2 bouyer fp->flags = 0;
503 1.4.2.2 bouyer break;
504 1.4.2.2 bouyer case 4:
505 1.4.2.2 bouyer strcpy(fp->name, AudioEslinear_le);
506 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
507 1.4.2.2 bouyer fp->precision = 16;
508 1.4.2.2 bouyer fp->flags = 0;
509 1.4.2.2 bouyer break;
510 1.4.2.2 bouyer case 5:
511 1.4.2.2 bouyer strcpy(fp->name, AudioEulinear_le);
512 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
513 1.4.2.2 bouyer fp->precision = 16;
514 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
515 1.4.2.2 bouyer break;
516 1.4.2.2 bouyer case 6:
517 1.4.2.2 bouyer strcpy(fp->name, AudioEslinear_be);
518 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
519 1.4.2.2 bouyer fp->precision = 16;
520 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
521 1.4.2.2 bouyer break;
522 1.4.2.2 bouyer case 7:
523 1.4.2.2 bouyer strcpy(fp->name, AudioEulinear_be);
524 1.4.2.2 bouyer fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
525 1.4.2.2 bouyer fp->precision = 16;
526 1.4.2.2 bouyer fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
527 1.4.2.2 bouyer break;
528 1.4.2.2 bouyer default:
529 1.4.2.2 bouyer return EINVAL;
530 1.4.2.2 bouyer }
531 1.4.2.2 bouyer return 0;
532 1.4.2.2 bouyer }
533 1.4.2.2 bouyer
534 1.4.2.2 bouyer
535 1.4.2.2 bouyer static int
536 1.4.2.2 bouyer cmpci_set_params(handle, setmode, usemode, play, rec)
537 1.4.2.2 bouyer void *handle;
538 1.4.2.2 bouyer int setmode, usemode;
539 1.4.2.2 bouyer struct audio_params *play, *rec;
540 1.4.2.2 bouyer {
541 1.4.2.2 bouyer int i;
542 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
543 1.4.2.2 bouyer
544 1.4.2.2 bouyer for (i = 0; i < 2; i++) {
545 1.4.2.2 bouyer int md_format;
546 1.4.2.2 bouyer int md_divide;
547 1.4.2.2 bouyer int md_index;
548 1.4.2.2 bouyer int mode;
549 1.4.2.2 bouyer struct audio_params *p;
550 1.4.2.2 bouyer
551 1.4.2.2 bouyer switch (i) {
552 1.4.2.2 bouyer case 0:
553 1.4.2.2 bouyer mode = AUMODE_PLAY;
554 1.4.2.2 bouyer p = play;
555 1.4.2.2 bouyer break;
556 1.4.2.2 bouyer case 1:
557 1.4.2.2 bouyer mode = AUMODE_RECORD;
558 1.4.2.2 bouyer p = rec;
559 1.4.2.2 bouyer break;
560 1.4.2.2 bouyer }
561 1.4.2.2 bouyer
562 1.4.2.2 bouyer if (!(setmode & mode))
563 1.4.2.2 bouyer continue;
564 1.4.2.2 bouyer
565 1.4.2.2 bouyer
566 1.4.2.2 bouyer /* format */
567 1.4.2.2 bouyer p->sw_code = NULL;
568 1.4.2.2 bouyer switch ( p->channels ) {
569 1.4.2.2 bouyer case 1:
570 1.4.2.2 bouyer md_format = CMPCI_REG_FORMAT_MONO;
571 1.4.2.2 bouyer break;
572 1.4.2.2 bouyer case 2:
573 1.4.2.2 bouyer md_format = CMPCI_REG_FORMAT_STEREO;
574 1.4.2.2 bouyer break;
575 1.4.2.2 bouyer default:
576 1.4.2.2 bouyer return (EINVAL);
577 1.4.2.2 bouyer }
578 1.4.2.2 bouyer switch (p->encoding) {
579 1.4.2.2 bouyer case AUDIO_ENCODING_ULAW:
580 1.4.2.2 bouyer if (p->precision != 8)
581 1.4.2.2 bouyer return (EINVAL);
582 1.4.2.2 bouyer if (mode & AUMODE_PLAY) {
583 1.4.2.2 bouyer p->factor = 2;
584 1.4.2.2 bouyer p->sw_code = mulaw_to_slinear16_le;
585 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
586 1.4.2.2 bouyer } else {
587 1.4.2.2 bouyer p->sw_code = ulinear8_to_mulaw;
588 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
589 1.4.2.2 bouyer }
590 1.4.2.2 bouyer break;
591 1.4.2.2 bouyer case AUDIO_ENCODING_ALAW:
592 1.4.2.2 bouyer if (p->precision != 8)
593 1.4.2.2 bouyer return (EINVAL);
594 1.4.2.2 bouyer if (mode & AUMODE_PLAY) {
595 1.4.2.2 bouyer p->factor = 2;
596 1.4.2.2 bouyer p->sw_code = alaw_to_slinear16_le;
597 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
598 1.4.2.2 bouyer } else {
599 1.4.2.2 bouyer p->sw_code = ulinear8_to_alaw;
600 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
601 1.4.2.2 bouyer }
602 1.4.2.2 bouyer break;
603 1.4.2.2 bouyer case AUDIO_ENCODING_SLINEAR_LE:
604 1.4.2.2 bouyer switch (p->precision) {
605 1.4.2.2 bouyer case 8:
606 1.4.2.2 bouyer p->sw_code = change_sign8;
607 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
608 1.4.2.2 bouyer break;
609 1.4.2.2 bouyer case 16:
610 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
611 1.4.2.2 bouyer break;
612 1.4.2.2 bouyer default:
613 1.4.2.2 bouyer return (EINVAL);
614 1.4.2.2 bouyer }
615 1.4.2.2 bouyer break;
616 1.4.2.2 bouyer case AUDIO_ENCODING_SLINEAR_BE:
617 1.4.2.2 bouyer switch (p->precision) {
618 1.4.2.2 bouyer case 8:
619 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
620 1.4.2.2 bouyer p->sw_code = change_sign8;
621 1.4.2.2 bouyer break;
622 1.4.2.2 bouyer case 16:
623 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
624 1.4.2.2 bouyer p->sw_code = swap_bytes;
625 1.4.2.2 bouyer break;
626 1.4.2.2 bouyer default:
627 1.4.2.2 bouyer return (EINVAL);
628 1.4.2.2 bouyer }
629 1.4.2.2 bouyer break;
630 1.4.2.2 bouyer case AUDIO_ENCODING_ULINEAR_LE:
631 1.4.2.2 bouyer switch (p->precision) {
632 1.4.2.2 bouyer case 8:
633 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
634 1.4.2.2 bouyer break;
635 1.4.2.2 bouyer case 16:
636 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
637 1.4.2.2 bouyer p->sw_code = change_sign16_le;
638 1.4.2.2 bouyer break;
639 1.4.2.2 bouyer default:
640 1.4.2.2 bouyer return (EINVAL);
641 1.4.2.2 bouyer }
642 1.4.2.2 bouyer break;
643 1.4.2.2 bouyer case AUDIO_ENCODING_ULINEAR_BE:
644 1.4.2.2 bouyer switch (p->precision) {
645 1.4.2.2 bouyer case 8:
646 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_8BIT;
647 1.4.2.2 bouyer break;
648 1.4.2.2 bouyer case 16:
649 1.4.2.2 bouyer md_format |= CMPCI_REG_FORMAT_16BIT;
650 1.4.2.2 bouyer if (mode & AUMODE_PLAY)
651 1.4.2.2 bouyer p->sw_code =swap_bytes_change_sign16_le;
652 1.4.2.2 bouyer else
653 1.4.2.2 bouyer p->sw_code =change_sign16_swap_bytes_le;
654 1.4.2.2 bouyer break;
655 1.4.2.2 bouyer default:
656 1.4.2.2 bouyer return (EINVAL);
657 1.4.2.2 bouyer }
658 1.4.2.2 bouyer break;
659 1.4.2.2 bouyer default:
660 1.4.2.2 bouyer return (EINVAL);
661 1.4.2.2 bouyer }
662 1.4.2.2 bouyer if (mode & AUMODE_PLAY)
663 1.4.2.2 bouyer cmpci_reg_partial_write_4(sc,
664 1.4.2.2 bouyer CMPCI_REG_CHANNEL_FORMAT, CMPCI_REG_CH0_FORMAT_SHIFT,
665 1.4.2.2 bouyer CMPCI_REG_CH0_FORMAT_MASK, md_format);
666 1.4.2.2 bouyer else
667 1.4.2.2 bouyer cmpci_reg_partial_write_4(sc,
668 1.4.2.2 bouyer CMPCI_REG_CHANNEL_FORMAT, CMPCI_REG_CH1_FORMAT_SHIFT,
669 1.4.2.2 bouyer CMPCI_REG_CH1_FORMAT_MASK, md_format);
670 1.4.2.2 bouyer /* sample rate */
671 1.4.2.2 bouyer md_index = cmpci_rate_to_index(p->sample_rate);
672 1.4.2.2 bouyer md_divide = cmpci_index_to_divider(md_index);
673 1.4.2.2 bouyer p->sample_rate = cmpci_index_to_rate(md_index);
674 1.4.2.2 bouyer #if 0
675 1.4.2.2 bouyer DPRINTF(("%s: sample:%d, divider=%d\n",
676 1.4.2.2 bouyer sc->sc_dev.dv_xname, (int)p->sample_rate, md_divide));
677 1.4.2.2 bouyer #endif
678 1.4.2.2 bouyer if (mode & AUMODE_PLAY) {
679 1.4.2.2 bouyer cmpci_reg_partial_write_4(sc,
680 1.4.2.2 bouyer CMPCI_REG_FUNC_1, CMPCI_REG_DAC_FS_SHIFT,
681 1.4.2.2 bouyer CMPCI_REG_DAC_FS_MASK, md_divide);
682 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
683 1.4.2.2 bouyer switch (md_divide) {
684 1.4.2.2 bouyer case CMPCI_REG_RATE_44100:
685 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_MISC,
686 1.4.2.2 bouyer CMPCI_REG_SPDIF_48K);
687 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_1,
688 1.4.2.2 bouyer CMPCI_REG_SPDIF_LOOP);
689 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_1,
690 1.4.2.2 bouyer CMPCI_REG_SPDIF0_ENABLE);
691 1.4.2.2 bouyer break;
692 1.4.2.2 bouyer case CMPCI_REG_RATE_48000:
693 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_MISC,
694 1.4.2.2 bouyer CMPCI_REG_SPDIF_48K);
695 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_1,
696 1.4.2.2 bouyer CMPCI_REG_SPDIF_LOOP);
697 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_1,
698 1.4.2.2 bouyer CMPCI_REG_SPDIF0_ENABLE);
699 1.4.2.2 bouyer break;
700 1.4.2.2 bouyer default:
701 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_1,
702 1.4.2.2 bouyer CMPCI_REG_SPDIF0_ENABLE);
703 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_1,
704 1.4.2.2 bouyer CMPCI_REG_SPDIF_LOOP);
705 1.4.2.2 bouyer }
706 1.4.2.2 bouyer #endif
707 1.4.2.2 bouyer } else {
708 1.4.2.2 bouyer cmpci_reg_partial_write_4(sc,
709 1.4.2.2 bouyer CMPCI_REG_FUNC_1, CMPCI_REG_ADC_FS_SHIFT,
710 1.4.2.2 bouyer CMPCI_REG_ADC_FS_MASK, md_divide);
711 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
712 1.4.2.2 bouyer if (sc->in_mask & CMPCI_SPDIF_IN) {
713 1.4.2.2 bouyer switch (md_divide) {
714 1.4.2.2 bouyer case CMPCI_REG_RATE_44100:
715 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_1,
716 1.4.2.2 bouyer CMPCI_REG_SPDIF1_ENABLE);
717 1.4.2.2 bouyer break;
718 1.4.2.2 bouyer default:
719 1.4.2.2 bouyer return EINVAL;
720 1.4.2.2 bouyer }
721 1.4.2.2 bouyer } else
722 1.4.2.2 bouyer cmpci_reg_clear_4(sc,
723 1.4.2.2 bouyer CMPCI_REG_FUNC_1, CMPCI_REG_SPDIF1_ENABLE);
724 1.4.2.2 bouyer #endif
725 1.4.2.2 bouyer }
726 1.4.2.2 bouyer }
727 1.4.2.2 bouyer return 0;
728 1.4.2.2 bouyer }
729 1.4.2.2 bouyer
730 1.4.2.2 bouyer /* ARGSUSED */
731 1.4.2.2 bouyer static int
732 1.4.2.2 bouyer cmpci_round_blocksize(handle, block)
733 1.4.2.2 bouyer void *handle;
734 1.4.2.2 bouyer int block;
735 1.4.2.2 bouyer {
736 1.4.2.2 bouyer return (block & -4);
737 1.4.2.2 bouyer }
738 1.4.2.2 bouyer
739 1.4.2.2 bouyer static int
740 1.4.2.2 bouyer cmpci_halt_output(handle)
741 1.4.2.2 bouyer void *handle;
742 1.4.2.2 bouyer {
743 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
744 1.4.2.2 bouyer int s;
745 1.4.2.2 bouyer
746 1.4.2.2 bouyer s = splaudio();
747 1.4.2.2 bouyer sc->sc_play.intr = NULL;
748 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_INTR_CTRL, CMPCI_REG_CH0_INTR_ENABLE);
749 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH0_ENABLE);
750 1.4.2.2 bouyer /* wait for reset DMA */
751 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH0_RESET);
752 1.4.2.2 bouyer delay(10);
753 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH0_RESET);
754 1.4.2.2 bouyer splx(s);
755 1.4.2.2 bouyer
756 1.4.2.2 bouyer return 0;
757 1.4.2.2 bouyer }
758 1.4.2.2 bouyer
759 1.4.2.2 bouyer static int
760 1.4.2.2 bouyer cmpci_halt_input(handle)
761 1.4.2.2 bouyer void *handle;
762 1.4.2.2 bouyer {
763 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
764 1.4.2.2 bouyer int s;
765 1.4.2.2 bouyer
766 1.4.2.2 bouyer s = splaudio();
767 1.4.2.2 bouyer sc->sc_rec.intr = NULL;
768 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_INTR_CTRL, CMPCI_REG_CH1_INTR_ENABLE);
769 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH1_ENABLE);
770 1.4.2.2 bouyer /* wait for reset DMA */
771 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH1_RESET);
772 1.4.2.2 bouyer delay(10);
773 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH1_RESET);
774 1.4.2.2 bouyer splx(s);
775 1.4.2.2 bouyer
776 1.4.2.2 bouyer return 0;
777 1.4.2.2 bouyer }
778 1.4.2.2 bouyer
779 1.4.2.2 bouyer
780 1.4.2.2 bouyer /* get audio device information */
781 1.4.2.2 bouyer static int
782 1.4.2.2 bouyer cmpci_getdev(handle, ad)
783 1.4.2.2 bouyer void *handle;
784 1.4.2.2 bouyer struct audio_device *ad;
785 1.4.2.2 bouyer {
786 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
787 1.4.2.2 bouyer
788 1.4.2.2 bouyer strncpy(ad->name, "CMI PCI Audio", sizeof(ad->name));
789 1.4.2.2 bouyer snprintf(ad->version, sizeof(ad->version), "0x%02x", sc->sc_revision);
790 1.4.2.2 bouyer switch (sc->sc_model) {
791 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8338A:
792 1.4.2.2 bouyer strncpy(ad->config, "CMI8338A", sizeof(ad->config));
793 1.4.2.2 bouyer break;
794 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8338B:
795 1.4.2.2 bouyer strncpy(ad->config, "CMI8338B", sizeof(ad->config));
796 1.4.2.2 bouyer break;
797 1.4.2.2 bouyer case PCI_PRODUCT_CMEDIA_CMI8738:
798 1.4.2.2 bouyer strncpy(ad->config, "CMI8738", sizeof(ad->config));
799 1.4.2.2 bouyer break;
800 1.4.2.2 bouyer default:
801 1.4.2.2 bouyer strncpy(ad->config, "unknown", sizeof(ad->config));
802 1.4.2.2 bouyer }
803 1.4.2.2 bouyer
804 1.4.2.2 bouyer return 0;
805 1.4.2.2 bouyer }
806 1.4.2.2 bouyer
807 1.4.2.2 bouyer
808 1.4.2.2 bouyer /* mixer device information */
809 1.4.2.2 bouyer int
810 1.4.2.2 bouyer cmpci_query_devinfo(handle, dip)
811 1.4.2.2 bouyer void *handle;
812 1.4.2.2 bouyer mixer_devinfo_t *dip;
813 1.4.2.2 bouyer {
814 1.4.2.2 bouyer #if 0
815 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
816 1.4.2.2 bouyer #endif
817 1.4.2.2 bouyer
818 1.4.2.2 bouyer switch (dip->index) {
819 1.4.2.2 bouyer case CMPCI_MASTER_VOL:
820 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
821 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
822 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
823 1.4.2.2 bouyer strcpy(dip->label.name, AudioNmaster);
824 1.4.2.2 bouyer dip->un.v.num_channels = 2;
825 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
826 1.4.2.2 bouyer return 0;
827 1.4.2.2 bouyer case CMPCI_FM_VOL:
828 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
829 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
830 1.4.2.2 bouyer dip->prev = AUDIO_MIXER_LAST;
831 1.4.2.2 bouyer dip->next = CMPCI_FM_IN_MUTE;
832 1.4.2.2 bouyer strcpy(dip->label.name, AudioNfmsynth);
833 1.4.2.2 bouyer dip->un.v.num_channels = 2;
834 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
835 1.4.2.2 bouyer return 0;
836 1.4.2.2 bouyer case CMPCI_CD_VOL:
837 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
838 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
839 1.4.2.2 bouyer dip->prev = AUDIO_MIXER_LAST;
840 1.4.2.2 bouyer dip->next = CMPCI_CD_IN_MUTE;
841 1.4.2.2 bouyer strcpy(dip->label.name, AudioNcd);
842 1.4.2.2 bouyer dip->un.v.num_channels = 2;
843 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
844 1.4.2.2 bouyer return 0;
845 1.4.2.2 bouyer case CMPCI_VOICE_VOL:
846 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
847 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
848 1.4.2.2 bouyer dip->prev = AUDIO_MIXER_LAST;
849 1.4.2.2 bouyer dip->next = AUDIO_MIXER_LAST;
850 1.4.2.2 bouyer strcpy(dip->label.name, AudioNdac);
851 1.4.2.2 bouyer dip->un.v.num_channels = 2;
852 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
853 1.4.2.2 bouyer return 0;
854 1.4.2.2 bouyer case CMPCI_OUTPUT_CLASS:
855 1.4.2.2 bouyer dip->type = AUDIO_MIXER_CLASS;
856 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
857 1.4.2.2 bouyer dip->next = dip->prev = AUDIO_MIXER_LAST;
858 1.4.2.2 bouyer strcpy(dip->label.name, AudioCoutputs);
859 1.4.2.2 bouyer return 0;
860 1.4.2.2 bouyer case CMPCI_MIC_VOL:
861 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
862 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
863 1.4.2.2 bouyer dip->prev = AUDIO_MIXER_LAST;
864 1.4.2.2 bouyer dip->next = CMPCI_MIC_IN_MUTE;
865 1.4.2.2 bouyer strcpy(dip->label.name, AudioNmicrophone);
866 1.4.2.2 bouyer dip->un.v.num_channels = 1;
867 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
868 1.4.2.2 bouyer return 0;
869 1.4.2.2 bouyer case CMPCI_LINE_IN_VOL:
870 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
871 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
872 1.4.2.2 bouyer dip->prev = AUDIO_MIXER_LAST;
873 1.4.2.2 bouyer dip->next = CMPCI_LINE_IN_MUTE;
874 1.4.2.2 bouyer strcpy(dip->label.name, AudioNline);
875 1.4.2.2 bouyer dip->un.v.num_channels = 2;
876 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
877 1.4.2.2 bouyer return 0;
878 1.4.2.2 bouyer case CMPCI_RECORD_SOURCE:
879 1.4.2.2 bouyer dip->mixer_class = CMPCI_RECORD_CLASS;
880 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
881 1.4.2.2 bouyer strcpy(dip->label.name, AudioNsource);
882 1.4.2.2 bouyer dip->type = AUDIO_MIXER_SET;
883 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
884 1.4.2.2 bouyer dip->un.s.num_mem = 5;
885 1.4.2.2 bouyer #else
886 1.4.2.2 bouyer dip->un.s.num_mem = 4;
887 1.4.2.2 bouyer #endif
888 1.4.2.2 bouyer strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
889 1.4.2.2 bouyer dip->un.s.member[0].mask = 1 << CMPCI_MIC_VOL;
890 1.4.2.2 bouyer strcpy(dip->un.s.member[1].label.name, AudioNcd);
891 1.4.2.2 bouyer dip->un.s.member[1].mask = 1 << CMPCI_CD_VOL;
892 1.4.2.2 bouyer strcpy(dip->un.s.member[2].label.name, AudioNline);
893 1.4.2.2 bouyer dip->un.s.member[2].mask = 1 << CMPCI_LINE_IN_VOL;
894 1.4.2.2 bouyer strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
895 1.4.2.2 bouyer dip->un.s.member[3].mask = 1 << CMPCI_FM_VOL;
896 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
897 1.4.2.2 bouyer strcpy(dip->un.s.member[4].label.name, CmpciNspdif);
898 1.4.2.2 bouyer dip->un.s.member[4].mask = 1 << CMPCI_SPDIF_IN;
899 1.4.2.2 bouyer #endif
900 1.4.2.2 bouyer return 0;
901 1.4.2.2 bouyer case CMPCI_BASS:
902 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
903 1.4.2.2 bouyer strcpy(dip->label.name, AudioNbass);
904 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
905 1.4.2.2 bouyer dip->mixer_class = CMPCI_EQUALIZATION_CLASS;
906 1.4.2.2 bouyer dip->un.v.num_channels = 2;
907 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNbass);
908 1.4.2.2 bouyer return 0;
909 1.4.2.2 bouyer case CMPCI_TREBLE:
910 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
911 1.4.2.2 bouyer strcpy(dip->label.name, AudioNtreble);
912 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
913 1.4.2.2 bouyer dip->mixer_class = CMPCI_EQUALIZATION_CLASS;
914 1.4.2.2 bouyer dip->un.v.num_channels = 2;
915 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNtreble);
916 1.4.2.2 bouyer return 0;
917 1.4.2.2 bouyer case CMPCI_RECORD_CLASS:
918 1.4.2.2 bouyer dip->type = AUDIO_MIXER_CLASS;
919 1.4.2.2 bouyer dip->mixer_class = CMPCI_RECORD_CLASS;
920 1.4.2.2 bouyer dip->next = dip->prev = AUDIO_MIXER_LAST;
921 1.4.2.2 bouyer strcpy(dip->label.name, AudioCrecord);
922 1.4.2.2 bouyer return 0;
923 1.4.2.2 bouyer case CMPCI_INPUT_CLASS:
924 1.4.2.2 bouyer dip->type = AUDIO_MIXER_CLASS;
925 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
926 1.4.2.2 bouyer dip->next = dip->prev = AUDIO_MIXER_LAST;
927 1.4.2.2 bouyer strcpy(dip->label.name, AudioCinputs);
928 1.4.2.2 bouyer return 0;
929 1.4.2.2 bouyer case CMPCI_PCSPEAKER:
930 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
931 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
932 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
933 1.4.2.2 bouyer strcpy(dip->label.name, "pc_speaker");
934 1.4.2.2 bouyer dip->un.v.num_channels = 1;
935 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
936 1.4.2.2 bouyer return 0;
937 1.4.2.2 bouyer case CMPCI_INPUT_GAIN:
938 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
939 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
940 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
941 1.4.2.2 bouyer strcpy(dip->label.name, AudioNinput);
942 1.4.2.2 bouyer dip->un.v.num_channels = 2;
943 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
944 1.4.2.2 bouyer return 0;
945 1.4.2.2 bouyer case CMPCI_OUTPUT_GAIN:
946 1.4.2.2 bouyer dip->type = AUDIO_MIXER_VALUE;
947 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
948 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
949 1.4.2.2 bouyer strcpy(dip->label.name, AudioNoutput);
950 1.4.2.2 bouyer dip->un.v.num_channels = 2;
951 1.4.2.2 bouyer strcpy(dip->un.v.units.name, AudioNvolume);
952 1.4.2.2 bouyer return 0;
953 1.4.2.2 bouyer case CMPCI_AGC:
954 1.4.2.2 bouyer dip->type = AUDIO_MIXER_ENUM;
955 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
956 1.4.2.2 bouyer dip->prev = dip->next = AUDIO_MIXER_LAST;
957 1.4.2.2 bouyer strcpy(dip->label.name, "agc");
958 1.4.2.2 bouyer dip->un.e.num_mem = 2;
959 1.4.2.2 bouyer strcpy(dip->un.e.member[0].label.name, AudioNoff);
960 1.4.2.2 bouyer dip->un.e.member[0].ord = 0;
961 1.4.2.2 bouyer strcpy(dip->un.e.member[1].label.name, AudioNon);
962 1.4.2.2 bouyer dip->un.e.member[1].ord = 1;
963 1.4.2.2 bouyer return 0;
964 1.4.2.2 bouyer case CMPCI_EQUALIZATION_CLASS:
965 1.4.2.2 bouyer dip->type = AUDIO_MIXER_CLASS;
966 1.4.2.2 bouyer dip->mixer_class = CMPCI_EQUALIZATION_CLASS;
967 1.4.2.2 bouyer dip->next = dip->prev = AUDIO_MIXER_LAST;
968 1.4.2.2 bouyer strcpy(dip->label.name, AudioCequalization);
969 1.4.2.2 bouyer return 0;
970 1.4.2.2 bouyer
971 1.4.2.2 bouyer case CMPCI_CD_IN_MUTE:
972 1.4.2.2 bouyer dip->prev = CMPCI_CD_VOL;
973 1.4.2.2 bouyer dip->next = CMPCI_CD_SWAP;
974 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
975 1.4.2.2 bouyer goto mute;
976 1.4.2.2 bouyer case CMPCI_MIC_IN_MUTE:
977 1.4.2.2 bouyer dip->prev = CMPCI_MIC_VOL;
978 1.4.2.2 bouyer dip->next = CMPCI_MIC_SWAP;
979 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
980 1.4.2.2 bouyer goto mute;
981 1.4.2.2 bouyer case CMPCI_LINE_IN_MUTE:
982 1.4.2.2 bouyer dip->prev = CMPCI_LINE_IN_VOL;
983 1.4.2.2 bouyer dip->next = CMPCI_LINE_SWAP;
984 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
985 1.4.2.2 bouyer goto mute;
986 1.4.2.2 bouyer case CMPCI_FM_IN_MUTE:
987 1.4.2.2 bouyer dip->prev = CMPCI_FM_VOL;
988 1.4.2.2 bouyer dip->next = CMPCI_FM_SWAP;
989 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
990 1.4.2.2 bouyer goto mute;
991 1.4.2.2 bouyer case CMPCI_CD_SWAP:
992 1.4.2.2 bouyer dip->prev = CMPCI_CD_IN_MUTE;
993 1.4.2.2 bouyer dip->next = CMPCI_CD_OUT_MUTE;
994 1.4.2.2 bouyer goto swap;
995 1.4.2.2 bouyer case CMPCI_MIC_SWAP:
996 1.4.2.2 bouyer dip->prev = CMPCI_MIC_IN_MUTE;
997 1.4.2.2 bouyer dip->next = CMPCI_MIC_OUT_MUTE;
998 1.4.2.2 bouyer goto swap;
999 1.4.2.2 bouyer case CMPCI_LINE_SWAP:
1000 1.4.2.2 bouyer dip->prev = CMPCI_LINE_IN_MUTE;
1001 1.4.2.2 bouyer dip->next = CMPCI_LINE_OUT_MUTE;
1002 1.4.2.2 bouyer goto swap;
1003 1.4.2.2 bouyer case CMPCI_FM_SWAP:
1004 1.4.2.2 bouyer dip->prev = CMPCI_FM_IN_MUTE;
1005 1.4.2.2 bouyer dip->next = AUDIO_MIXER_LAST;
1006 1.4.2.2 bouyer swap:
1007 1.4.2.2 bouyer dip->mixer_class = CMPCI_INPUT_CLASS;
1008 1.4.2.2 bouyer strcpy(dip->label.name, AudioNswap);
1009 1.4.2.2 bouyer goto mute1;
1010 1.4.2.2 bouyer
1011 1.4.2.2 bouyer case CMPCI_CD_OUT_MUTE:
1012 1.4.2.2 bouyer dip->prev = CMPCI_CD_SWAP;
1013 1.4.2.2 bouyer dip->next = AUDIO_MIXER_LAST;
1014 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
1015 1.4.2.2 bouyer goto mute;
1016 1.4.2.2 bouyer case CMPCI_MIC_OUT_MUTE:
1017 1.4.2.2 bouyer dip->prev = CMPCI_MIC_SWAP;
1018 1.4.2.2 bouyer dip->next = AUDIO_MIXER_LAST;
1019 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
1020 1.4.2.2 bouyer goto mute;
1021 1.4.2.2 bouyer case CMPCI_LINE_OUT_MUTE:
1022 1.4.2.2 bouyer dip->prev = CMPCI_LINE_SWAP;
1023 1.4.2.2 bouyer dip->next = AUDIO_MIXER_LAST;
1024 1.4.2.2 bouyer dip->mixer_class = CMPCI_OUTPUT_CLASS;
1025 1.4.2.2 bouyer mute:
1026 1.4.2.2 bouyer strcpy(dip->label.name, AudioNmute);
1027 1.4.2.2 bouyer mute1:
1028 1.4.2.2 bouyer dip->type = AUDIO_MIXER_ENUM;
1029 1.4.2.2 bouyer dip->un.e.num_mem = 2;
1030 1.4.2.2 bouyer strcpy(dip->un.e.member[0].label.name, AudioNoff);
1031 1.4.2.2 bouyer dip->un.e.member[0].ord = 0;
1032 1.4.2.2 bouyer strcpy(dip->un.e.member[1].label.name, AudioNon);
1033 1.4.2.2 bouyer dip->un.e.member[1].ord = 1;
1034 1.4.2.2 bouyer return 0;
1035 1.4.2.2 bouyer }
1036 1.4.2.2 bouyer
1037 1.4.2.2 bouyer return ENXIO;
1038 1.4.2.2 bouyer }
1039 1.4.2.2 bouyer
1040 1.4.2.2 bouyer static int
1041 1.4.2.2 bouyer cmpci_alloc_dmamem(sc, size, type, flags, r_addr)
1042 1.4.2.2 bouyer struct cmpci_softc *sc;
1043 1.4.2.2 bouyer size_t size;
1044 1.4.2.2 bouyer int type, flags;
1045 1.4.2.2 bouyer caddr_t *r_addr;
1046 1.4.2.2 bouyer {
1047 1.4.2.2 bouyer int error = 0;
1048 1.4.2.2 bouyer struct cmpci_dmanode *n;
1049 1.4.2.2 bouyer int w;
1050 1.4.2.2 bouyer
1051 1.4.2.2 bouyer n = malloc(sizeof(struct cmpci_dmanode), type, flags);
1052 1.4.2.2 bouyer if (n == NULL) {
1053 1.4.2.2 bouyer error = ENOMEM;
1054 1.4.2.2 bouyer goto quit;
1055 1.4.2.2 bouyer }
1056 1.4.2.2 bouyer
1057 1.4.2.2 bouyer w = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
1058 1.4.2.2 bouyer #define CMPCI_DMABUF_ALIGN 0x4
1059 1.4.2.2 bouyer #define CMPCI_DMABUF_BOUNDARY 0x0
1060 1.4.2.2 bouyer n->cd_tag = sc->sc_dmat;
1061 1.4.2.2 bouyer n->cd_size = size;
1062 1.4.2.2 bouyer error = bus_dmamem_alloc(n->cd_tag, n->cd_size,
1063 1.4.2.2 bouyer CMPCI_DMABUF_ALIGN, CMPCI_DMABUF_BOUNDARY, n->cd_segs,
1064 1.4.2.2 bouyer sizeof(n->cd_segs)/sizeof(n->cd_segs[0]), &n->cd_nsegs, w);
1065 1.4.2.2 bouyer if (error)
1066 1.4.2.2 bouyer goto mfree;
1067 1.4.2.2 bouyer error = bus_dmamem_map(n->cd_tag, n->cd_segs, n->cd_nsegs, n->cd_size,
1068 1.4.2.2 bouyer &n->cd_addr, w | BUS_DMA_COHERENT);
1069 1.4.2.2 bouyer if (error)
1070 1.4.2.2 bouyer goto dmafree;
1071 1.4.2.2 bouyer error = bus_dmamap_create(n->cd_tag, n->cd_size, 1, n->cd_size, 0,
1072 1.4.2.2 bouyer w, &n->cd_map);
1073 1.4.2.2 bouyer if (error)
1074 1.4.2.2 bouyer goto unmap;
1075 1.4.2.2 bouyer error = bus_dmamap_load(n->cd_tag, n->cd_map, n->cd_addr, n->cd_size,
1076 1.4.2.2 bouyer NULL, w);
1077 1.4.2.2 bouyer if (error)
1078 1.4.2.2 bouyer goto destroy;
1079 1.4.2.2 bouyer
1080 1.4.2.2 bouyer n->cd_next = sc->sc_dmap;
1081 1.4.2.2 bouyer sc->sc_dmap = n;
1082 1.4.2.2 bouyer *r_addr = KVADDR(n);
1083 1.4.2.2 bouyer return 0;
1084 1.4.2.2 bouyer
1085 1.4.2.2 bouyer destroy:
1086 1.4.2.2 bouyer bus_dmamap_destroy(n->cd_tag, n->cd_map);
1087 1.4.2.2 bouyer unmap:
1088 1.4.2.2 bouyer bus_dmamem_unmap(n->cd_tag, n->cd_addr, n->cd_size);
1089 1.4.2.2 bouyer dmafree:
1090 1.4.2.2 bouyer bus_dmamem_free(n->cd_tag,
1091 1.4.2.2 bouyer n->cd_segs, sizeof(n->cd_segs)/sizeof(n->cd_segs[0]));
1092 1.4.2.2 bouyer mfree:
1093 1.4.2.2 bouyer free(n, type);
1094 1.4.2.2 bouyer quit:
1095 1.4.2.2 bouyer return error;
1096 1.4.2.2 bouyer }
1097 1.4.2.2 bouyer
1098 1.4.2.2 bouyer static int
1099 1.4.2.2 bouyer cmpci_free_dmamem(sc, addr, type)
1100 1.4.2.2 bouyer struct cmpci_softc *sc;
1101 1.4.2.2 bouyer caddr_t addr;
1102 1.4.2.2 bouyer int type;
1103 1.4.2.2 bouyer {
1104 1.4.2.2 bouyer struct cmpci_dmanode **nnp;
1105 1.4.2.2 bouyer
1106 1.4.2.2 bouyer for (nnp = &sc->sc_dmap; *nnp; nnp= &(*nnp)->cd_next) {
1107 1.4.2.2 bouyer if ((*nnp)->cd_addr == addr) {
1108 1.4.2.2 bouyer struct cmpci_dmanode *n = *nnp;
1109 1.4.2.2 bouyer bus_dmamap_unload(n->cd_tag, n->cd_map);
1110 1.4.2.2 bouyer bus_dmamap_destroy(n->cd_tag, n->cd_map);
1111 1.4.2.2 bouyer bus_dmamem_unmap(n->cd_tag, n->cd_addr, n->cd_size);
1112 1.4.2.2 bouyer bus_dmamem_free(n->cd_tag, n->cd_segs,
1113 1.4.2.2 bouyer sizeof(n->cd_segs)/sizeof(n->cd_segs[0]));
1114 1.4.2.2 bouyer free(n, type);
1115 1.4.2.2 bouyer return 0;
1116 1.4.2.2 bouyer }
1117 1.4.2.2 bouyer }
1118 1.4.2.2 bouyer return -1;
1119 1.4.2.2 bouyer }
1120 1.4.2.2 bouyer
1121 1.4.2.2 bouyer static struct cmpci_dmanode *
1122 1.4.2.2 bouyer cmpci_find_dmamem(sc, addr)
1123 1.4.2.2 bouyer struct cmpci_softc *sc;
1124 1.4.2.2 bouyer caddr_t addr;
1125 1.4.2.2 bouyer {
1126 1.4.2.2 bouyer struct cmpci_dmanode *p;
1127 1.4.2.2 bouyer for (p=sc->sc_dmap; p; p=p->cd_next)
1128 1.4.2.2 bouyer if ( KVADDR(p) == (void *)addr )
1129 1.4.2.2 bouyer break;
1130 1.4.2.2 bouyer return p;
1131 1.4.2.2 bouyer }
1132 1.4.2.2 bouyer
1133 1.4.2.2 bouyer
1134 1.4.2.2 bouyer #if 0
1135 1.4.2.2 bouyer static void
1136 1.4.2.2 bouyer cmpci_print_dmamem __P((struct cmpci_dmanode *p));
1137 1.4.2.2 bouyer static void
1138 1.4.2.2 bouyer cmpci_print_dmamem(p)
1139 1.4.2.2 bouyer struct cmpci_dmanode *p;
1140 1.4.2.2 bouyer {
1141 1.4.2.2 bouyer DPRINTF(("DMA at virt:%p, dmaseg:%p, mapseg:%p, size:%p\n",
1142 1.4.2.2 bouyer (void *)p->cd_addr, (void *)p->cd_segs[0].ds_addr,
1143 1.4.2.2 bouyer (void *)DMAADDR(p), (void *)p->cd_size));
1144 1.4.2.2 bouyer }
1145 1.4.2.2 bouyer #endif /* DEBUG */
1146 1.4.2.2 bouyer
1147 1.4.2.2 bouyer
1148 1.4.2.2 bouyer static void *
1149 1.4.2.2 bouyer cmpci_allocm(handle, direction, size, type, flags)
1150 1.4.2.2 bouyer void *handle;
1151 1.4.2.2 bouyer int direction;
1152 1.4.2.2 bouyer size_t size;
1153 1.4.2.2 bouyer int type, flags;
1154 1.4.2.2 bouyer {
1155 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1156 1.4.2.2 bouyer caddr_t addr;
1157 1.4.2.2 bouyer
1158 1.4.2.2 bouyer if (cmpci_alloc_dmamem(sc, size, type, flags, &addr))
1159 1.4.2.2 bouyer return NULL;
1160 1.4.2.2 bouyer return addr;
1161 1.4.2.2 bouyer }
1162 1.4.2.2 bouyer
1163 1.4.2.2 bouyer static void
1164 1.4.2.2 bouyer cmpci_freem(handle, addr, type)
1165 1.4.2.2 bouyer void *handle;
1166 1.4.2.2 bouyer void *addr;
1167 1.4.2.2 bouyer int type;
1168 1.4.2.2 bouyer {
1169 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1170 1.4.2.2 bouyer
1171 1.4.2.2 bouyer cmpci_free_dmamem(sc, addr, type);
1172 1.4.2.2 bouyer }
1173 1.4.2.2 bouyer
1174 1.4.2.2 bouyer
1175 1.4.2.2 bouyer #define MAXVAL 256
1176 1.4.2.2 bouyer static int
1177 1.4.2.2 bouyer cmpci_adjust(val, mask)
1178 1.4.2.2 bouyer int val, mask;
1179 1.4.2.2 bouyer {
1180 1.4.2.2 bouyer val += (MAXVAL - mask) >> 1;
1181 1.4.2.2 bouyer if (val >= MAXVAL)
1182 1.4.2.2 bouyer val = MAXVAL-1;
1183 1.4.2.2 bouyer return val & mask;
1184 1.4.2.2 bouyer }
1185 1.4.2.2 bouyer
1186 1.4.2.2 bouyer static void
1187 1.4.2.2 bouyer cmpci_set_mixer_gain(sc, port)
1188 1.4.2.2 bouyer struct cmpci_softc *sc;
1189 1.4.2.2 bouyer int port;
1190 1.4.2.2 bouyer {
1191 1.4.2.2 bouyer int src;
1192 1.4.2.2 bouyer
1193 1.4.2.2 bouyer switch (port) {
1194 1.4.2.2 bouyer case CMPCI_MIC_VOL:
1195 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_MIC;
1196 1.4.2.2 bouyer break;
1197 1.4.2.2 bouyer case CMPCI_MASTER_VOL:
1198 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_MASTER_L;
1199 1.4.2.2 bouyer break;
1200 1.4.2.2 bouyer case CMPCI_LINE_IN_VOL:
1201 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_LINE_L;
1202 1.4.2.2 bouyer break;
1203 1.4.2.2 bouyer case CMPCI_VOICE_VOL:
1204 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_VOICE_L;
1205 1.4.2.2 bouyer break;
1206 1.4.2.2 bouyer case CMPCI_FM_VOL:
1207 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_FM_L;
1208 1.4.2.2 bouyer break;
1209 1.4.2.2 bouyer case CMPCI_CD_VOL:
1210 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_CDDA_L;
1211 1.4.2.2 bouyer break;
1212 1.4.2.2 bouyer case CMPCI_INPUT_GAIN:
1213 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_INGAIN_L;
1214 1.4.2.2 bouyer break;
1215 1.4.2.2 bouyer case CMPCI_OUTPUT_GAIN:
1216 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_OUTGAIN_L;
1217 1.4.2.2 bouyer break;
1218 1.4.2.2 bouyer case CMPCI_TREBLE:
1219 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_TREBLE_L;
1220 1.4.2.2 bouyer break;
1221 1.4.2.2 bouyer case CMPCI_BASS:
1222 1.4.2.2 bouyer src = CMPCI_SB16_MIXER_BASS_L;
1223 1.4.2.2 bouyer break;
1224 1.4.2.2 bouyer case CMPCI_PCSPEAKER:
1225 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_SPEAKER,
1226 1.4.2.2 bouyer sc->gain[port][CMPCI_LEFT]);
1227 1.4.2.2 bouyer return;
1228 1.4.2.2 bouyer default:
1229 1.4.2.2 bouyer return;
1230 1.4.2.2 bouyer }
1231 1.4.2.2 bouyer cmpci_mixerreg_write(sc, src, sc->gain[port][CMPCI_LEFT]);
1232 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_L_TO_R(src),
1233 1.4.2.2 bouyer sc->gain[port][CMPCI_RIGHT]);
1234 1.4.2.2 bouyer }
1235 1.4.2.2 bouyer
1236 1.4.2.2 bouyer static int
1237 1.4.2.2 bouyer cmpci_set_in_ports(sc, mask)
1238 1.4.2.2 bouyer struct cmpci_softc *sc;
1239 1.4.2.2 bouyer int mask;
1240 1.4.2.2 bouyer {
1241 1.4.2.2 bouyer int bitsl, bitsr;
1242 1.4.2.2 bouyer
1243 1.4.2.2 bouyer if (mask & ~((1<<CMPCI_FM_VOL) | (1<<CMPCI_LINE_IN_VOL) |
1244 1.4.2.2 bouyer (1<<CMPCI_CD_VOL) | (1<<CMPCI_MIC_VOL)
1245 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
1246 1.4.2.2 bouyer | (1<<CMPCI_SPDIF_IN)
1247 1.4.2.2 bouyer #endif
1248 1.4.2.2 bouyer ))
1249 1.4.2.2 bouyer return EINVAL;
1250 1.4.2.2 bouyer bitsr = 0;
1251 1.4.2.2 bouyer if (mask & (1<<CMPCI_FM_VOL)) bitsr |= CMPCI_SB16_MIXER_FM_SRC_R;
1252 1.4.2.2 bouyer if (mask & (1<<CMPCI_LINE_IN_VOL)) bitsr |= CMPCI_SB16_MIXER_LINE_SRC_R;
1253 1.4.2.2 bouyer if (mask & (1<<CMPCI_CD_VOL)) bitsr |= CMPCI_SB16_MIXER_CD_SRC_R;
1254 1.4.2.2 bouyer bitsl = CMPCI_SB16_MIXER_SRC_R_TO_L(bitsr);
1255 1.4.2.2 bouyer if (mask & (1<<CMPCI_MIC_VOL)) {
1256 1.4.2.2 bouyer bitsl |= CMPCI_SB16_MIXER_MIC_SRC;
1257 1.4.2.2 bouyer bitsr |= CMPCI_SB16_MIXER_MIC_SRC;
1258 1.4.2.2 bouyer }
1259 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_L, bitsl);
1260 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_R, bitsr);
1261 1.4.2.2 bouyer
1262 1.4.2.2 bouyer sc->in_mask = mask;
1263 1.4.2.2 bouyer
1264 1.4.2.2 bouyer return 0;
1265 1.4.2.2 bouyer }
1266 1.4.2.2 bouyer
1267 1.4.2.2 bouyer static int
1268 1.4.2.2 bouyer cmpci_set_port(handle, cp)
1269 1.4.2.2 bouyer void *handle;
1270 1.4.2.2 bouyer mixer_ctrl_t *cp;
1271 1.4.2.2 bouyer {
1272 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1273 1.4.2.2 bouyer int lgain, rgain;
1274 1.4.2.2 bouyer int mask, bits;
1275 1.4.2.2 bouyer int lmask, rmask, lbits, rbits;
1276 1.4.2.2 bouyer int mute, swap;
1277 1.4.2.2 bouyer
1278 1.4.2.2 bouyer switch (cp->dev) {
1279 1.4.2.2 bouyer case CMPCI_TREBLE:
1280 1.4.2.2 bouyer case CMPCI_BASS:
1281 1.4.2.2 bouyer case CMPCI_PCSPEAKER:
1282 1.4.2.2 bouyer case CMPCI_INPUT_GAIN:
1283 1.4.2.2 bouyer case CMPCI_OUTPUT_GAIN:
1284 1.4.2.2 bouyer case CMPCI_MIC_VOL:
1285 1.4.2.2 bouyer case CMPCI_LINE_IN_VOL:
1286 1.4.2.2 bouyer case CMPCI_VOICE_VOL:
1287 1.4.2.2 bouyer case CMPCI_FM_VOL:
1288 1.4.2.2 bouyer case CMPCI_CD_VOL:
1289 1.4.2.2 bouyer case CMPCI_MASTER_VOL:
1290 1.4.2.2 bouyer if (cp->type != AUDIO_MIXER_VALUE)
1291 1.4.2.2 bouyer return EINVAL;
1292 1.4.2.2 bouyer switch (cp->dev) {
1293 1.4.2.2 bouyer case CMPCI_MIC_VOL:
1294 1.4.2.2 bouyer if (cp->un.value.num_channels != 1)
1295 1.4.2.2 bouyer return EINVAL;
1296 1.4.2.2 bouyer
1297 1.4.2.2 bouyer lgain = rgain =
1298 1.4.2.2 bouyer CMPCI_ADJUST_MIC_GAIN(sc,
1299 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1300 1.4.2.2 bouyer break;
1301 1.4.2.2 bouyer case CMPCI_PCSPEAKER:
1302 1.4.2.2 bouyer if (cp->un.value.num_channels != 1)
1303 1.4.2.2 bouyer return EINVAL;
1304 1.4.2.2 bouyer /* fall into */
1305 1.4.2.2 bouyer case CMPCI_INPUT_GAIN:
1306 1.4.2.2 bouyer case CMPCI_OUTPUT_GAIN:
1307 1.4.2.2 bouyer lgain = rgain = CMPCI_ADJUST_2_GAIN(sc,
1308 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1309 1.4.2.2 bouyer break;
1310 1.4.2.2 bouyer default:
1311 1.4.2.2 bouyer switch (cp->un.value.num_channels) {
1312 1.4.2.2 bouyer case 1:
1313 1.4.2.2 bouyer lgain = rgain = CMPCI_ADJUST_GAIN(sc,
1314 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1315 1.4.2.2 bouyer break;
1316 1.4.2.2 bouyer case 2:
1317 1.4.2.2 bouyer lgain = CMPCI_ADJUST_GAIN(sc,
1318 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]);
1319 1.4.2.2 bouyer rgain = CMPCI_ADJUST_GAIN(sc,
1320 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
1321 1.4.2.2 bouyer break;
1322 1.4.2.2 bouyer default:
1323 1.4.2.2 bouyer return EINVAL;
1324 1.4.2.2 bouyer }
1325 1.4.2.2 bouyer break;
1326 1.4.2.2 bouyer }
1327 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_LEFT] = lgain;
1328 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_RIGHT] = rgain;
1329 1.4.2.2 bouyer
1330 1.4.2.2 bouyer cmpci_set_mixer_gain(sc, cp->dev);
1331 1.4.2.2 bouyer break;
1332 1.4.2.2 bouyer
1333 1.4.2.2 bouyer case CMPCI_RECORD_SOURCE:
1334 1.4.2.2 bouyer if (cp->type != AUDIO_MIXER_SET)
1335 1.4.2.2 bouyer return EINVAL;
1336 1.4.2.2 bouyer #ifdef CMPCI_SPDIF_SUPPORT
1337 1.4.2.2 bouyer if (cp->un.mask & (1<<CMPCI_SPDIF_IN))
1338 1.4.2.2 bouyer cp->un.mask = 1<<CMPCI_SPDIF_IN;
1339 1.4.2.2 bouyer #endif
1340 1.4.2.2 bouyer return cmpci_set_in_ports(sc, cp->un.mask);
1341 1.4.2.2 bouyer
1342 1.4.2.2 bouyer case CMPCI_AGC:
1343 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_AGC, cp->un.ord & 1);
1344 1.4.2.2 bouyer break;
1345 1.4.2.2 bouyer
1346 1.4.2.2 bouyer case CMPCI_CD_OUT_MUTE:
1347 1.4.2.2 bouyer mask = CMPCI_SB16_SW_CD;
1348 1.4.2.2 bouyer goto omute;
1349 1.4.2.2 bouyer case CMPCI_MIC_OUT_MUTE:
1350 1.4.2.2 bouyer mask = CMPCI_SB16_SW_MIC;
1351 1.4.2.2 bouyer goto omute;
1352 1.4.2.2 bouyer case CMPCI_LINE_OUT_MUTE:
1353 1.4.2.2 bouyer mask = CMPCI_SB16_SW_LINE;
1354 1.4.2.2 bouyer omute:
1355 1.4.2.2 bouyer if (cp->type != AUDIO_MIXER_ENUM)
1356 1.4.2.2 bouyer return EINVAL;
1357 1.4.2.2 bouyer bits = cmpci_mixerreg_read(sc, CMPCI_SB16_MIXER_OUTMIX);
1358 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_LR] = cp->un.ord != 0;
1359 1.4.2.2 bouyer if (cp->un.ord)
1360 1.4.2.2 bouyer bits = bits & ~mask;
1361 1.4.2.2 bouyer else
1362 1.4.2.2 bouyer bits = bits | mask;
1363 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_OUTMIX, bits);
1364 1.4.2.2 bouyer break;
1365 1.4.2.2 bouyer
1366 1.4.2.2 bouyer case CMPCI_MIC_IN_MUTE:
1367 1.4.2.2 bouyer case CMPCI_MIC_SWAP:
1368 1.4.2.2 bouyer lmask = rmask = CMPCI_SB16_SW_MIC;
1369 1.4.2.2 bouyer goto imute;
1370 1.4.2.2 bouyer case CMPCI_CD_IN_MUTE:
1371 1.4.2.2 bouyer case CMPCI_CD_SWAP:
1372 1.4.2.2 bouyer lmask = CMPCI_SB16_SW_CD_L;
1373 1.4.2.2 bouyer rmask = CMPCI_SB16_SW_CD_R;
1374 1.4.2.2 bouyer goto imute;
1375 1.4.2.2 bouyer case CMPCI_LINE_IN_MUTE:
1376 1.4.2.2 bouyer case CMPCI_LINE_SWAP:
1377 1.4.2.2 bouyer lmask = CMPCI_SB16_SW_LINE_L;
1378 1.4.2.2 bouyer rmask = CMPCI_SB16_SW_LINE_R;
1379 1.4.2.2 bouyer goto imute;
1380 1.4.2.2 bouyer case CMPCI_FM_IN_MUTE:
1381 1.4.2.2 bouyer case CMPCI_FM_SWAP:
1382 1.4.2.2 bouyer lmask = CMPCI_SB16_SW_FM_L;
1383 1.4.2.2 bouyer rmask = CMPCI_SB16_SW_FM_R;
1384 1.4.2.2 bouyer imute:
1385 1.4.2.2 bouyer if (cp->type != AUDIO_MIXER_ENUM)
1386 1.4.2.2 bouyer return EINVAL;
1387 1.4.2.2 bouyer mask = lmask | rmask;
1388 1.4.2.2 bouyer lbits = cmpci_mixerreg_read(sc, CMPCI_SB16_MIXER_ADCMIX_L)
1389 1.4.2.2 bouyer & ~mask;
1390 1.4.2.2 bouyer rbits = cmpci_mixerreg_read(sc, CMPCI_SB16_MIXER_ADCMIX_R)
1391 1.4.2.2 bouyer & ~mask;
1392 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_LR] = cp->un.ord != 0;
1393 1.4.2.2 bouyer if (CMPCI_IS_IN_MUTE(cp->dev)) {
1394 1.4.2.2 bouyer mute = cp->dev;
1395 1.4.2.2 bouyer swap = mute - CMPCI_CD_IN_MUTE + CMPCI_CD_SWAP;
1396 1.4.2.2 bouyer } else {
1397 1.4.2.2 bouyer swap = cp->dev;
1398 1.4.2.2 bouyer mute = swap + CMPCI_CD_IN_MUTE - CMPCI_CD_SWAP;
1399 1.4.2.2 bouyer }
1400 1.4.2.2 bouyer if (sc->gain[swap][CMPCI_LR]) {
1401 1.4.2.2 bouyer mask = lmask;
1402 1.4.2.2 bouyer lmask = rmask;
1403 1.4.2.2 bouyer rmask = mask;
1404 1.4.2.2 bouyer }
1405 1.4.2.2 bouyer if (!sc->gain[mute][CMPCI_LR]) {
1406 1.4.2.2 bouyer lbits = lbits | lmask;
1407 1.4.2.2 bouyer rbits = rbits | rmask;
1408 1.4.2.2 bouyer }
1409 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_L, lbits);
1410 1.4.2.2 bouyer cmpci_mixerreg_write(sc, CMPCI_SB16_MIXER_ADCMIX_R, rbits);
1411 1.4.2.2 bouyer break;
1412 1.4.2.2 bouyer
1413 1.4.2.2 bouyer default:
1414 1.4.2.2 bouyer return EINVAL;
1415 1.4.2.2 bouyer }
1416 1.4.2.2 bouyer
1417 1.4.2.2 bouyer return 0;
1418 1.4.2.2 bouyer }
1419 1.4.2.2 bouyer
1420 1.4.2.2 bouyer static int
1421 1.4.2.2 bouyer cmpci_get_port(handle, cp)
1422 1.4.2.2 bouyer void *handle;
1423 1.4.2.2 bouyer mixer_ctrl_t *cp;
1424 1.4.2.2 bouyer {
1425 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1426 1.4.2.2 bouyer
1427 1.4.2.2 bouyer switch (cp->dev) {
1428 1.4.2.2 bouyer case CMPCI_MIC_VOL:
1429 1.4.2.2 bouyer case CMPCI_LINE_IN_VOL:
1430 1.4.2.2 bouyer if (cp->un.value.num_channels != 1)
1431 1.4.2.2 bouyer return EINVAL;
1432 1.4.2.2 bouyer /* fall into */
1433 1.4.2.2 bouyer case CMPCI_TREBLE:
1434 1.4.2.2 bouyer case CMPCI_BASS:
1435 1.4.2.2 bouyer case CMPCI_PCSPEAKER:
1436 1.4.2.2 bouyer case CMPCI_INPUT_GAIN:
1437 1.4.2.2 bouyer case CMPCI_OUTPUT_GAIN:
1438 1.4.2.2 bouyer case CMPCI_VOICE_VOL:
1439 1.4.2.2 bouyer case CMPCI_FM_VOL:
1440 1.4.2.2 bouyer case CMPCI_CD_VOL:
1441 1.4.2.2 bouyer case CMPCI_MASTER_VOL:
1442 1.4.2.2 bouyer switch (cp->un.value.num_channels) {
1443 1.4.2.2 bouyer case 1:
1444 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
1445 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_LEFT];
1446 1.4.2.2 bouyer break;
1447 1.4.2.2 bouyer case 2:
1448 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
1449 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_LEFT];
1450 1.4.2.2 bouyer cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
1451 1.4.2.2 bouyer sc->gain[cp->dev][CMPCI_RIGHT];
1452 1.4.2.2 bouyer break;
1453 1.4.2.2 bouyer default:
1454 1.4.2.2 bouyer return EINVAL;
1455 1.4.2.2 bouyer }
1456 1.4.2.2 bouyer break;
1457 1.4.2.2 bouyer
1458 1.4.2.2 bouyer case CMPCI_RECORD_SOURCE:
1459 1.4.2.2 bouyer cp->un.mask = sc->in_mask;
1460 1.4.2.2 bouyer break;
1461 1.4.2.2 bouyer
1462 1.4.2.2 bouyer case CMPCI_AGC:
1463 1.4.2.2 bouyer cp->un.ord = cmpci_mixerreg_read(sc, CMPCI_SB16_MIXER_AGC);
1464 1.4.2.2 bouyer break;
1465 1.4.2.2 bouyer
1466 1.4.2.2 bouyer case CMPCI_CD_IN_MUTE:
1467 1.4.2.2 bouyer case CMPCI_MIC_IN_MUTE:
1468 1.4.2.2 bouyer case CMPCI_LINE_IN_MUTE:
1469 1.4.2.2 bouyer case CMPCI_FM_IN_MUTE:
1470 1.4.2.2 bouyer case CMPCI_CD_SWAP:
1471 1.4.2.2 bouyer case CMPCI_MIC_SWAP:
1472 1.4.2.2 bouyer case CMPCI_LINE_SWAP:
1473 1.4.2.2 bouyer case CMPCI_FM_SWAP:
1474 1.4.2.2 bouyer case CMPCI_CD_OUT_MUTE:
1475 1.4.2.2 bouyer case CMPCI_MIC_OUT_MUTE:
1476 1.4.2.2 bouyer case CMPCI_LINE_OUT_MUTE:
1477 1.4.2.2 bouyer cp->un.ord = sc->gain[cp->dev][CMPCI_LR];
1478 1.4.2.2 bouyer break;
1479 1.4.2.2 bouyer
1480 1.4.2.2 bouyer default:
1481 1.4.2.2 bouyer return EINVAL;
1482 1.4.2.2 bouyer }
1483 1.4.2.2 bouyer
1484 1.4.2.2 bouyer return 0;
1485 1.4.2.2 bouyer }
1486 1.4.2.2 bouyer
1487 1.4.2.2 bouyer /* ARGSUSED */
1488 1.4.2.2 bouyer static size_t
1489 1.4.2.2 bouyer cmpci_round_buffersize(handle, direction, bufsize)
1490 1.4.2.2 bouyer void *handle;
1491 1.4.2.2 bouyer int direction;
1492 1.4.2.2 bouyer size_t bufsize;
1493 1.4.2.2 bouyer {
1494 1.4.2.2 bouyer if (bufsize > 0x10000)
1495 1.4.2.2 bouyer bufsize = 0x10000;
1496 1.4.2.2 bouyer
1497 1.4.2.2 bouyer return bufsize;
1498 1.4.2.2 bouyer }
1499 1.4.2.2 bouyer
1500 1.4.2.2 bouyer
1501 1.4.2.2 bouyer static paddr_t
1502 1.4.2.2 bouyer cmpci_mappage(handle, addr, offset, prot)
1503 1.4.2.2 bouyer void *handle;
1504 1.4.2.2 bouyer void *addr;
1505 1.4.2.2 bouyer off_t offset;
1506 1.4.2.2 bouyer int prot;
1507 1.4.2.2 bouyer {
1508 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1509 1.4.2.2 bouyer struct cmpci_dmanode *p;
1510 1.4.2.2 bouyer
1511 1.4.2.2 bouyer if (offset < 0 || NULL == (p = cmpci_find_dmamem(sc, addr)))
1512 1.4.2.2 bouyer return -1;
1513 1.4.2.2 bouyer
1514 1.4.2.2 bouyer return bus_dmamem_mmap(p->cd_tag, p->cd_segs,
1515 1.4.2.2 bouyer sizeof(p->cd_segs)/sizeof(p->cd_segs[0]),
1516 1.4.2.2 bouyer offset, prot, BUS_DMA_WAITOK);
1517 1.4.2.2 bouyer }
1518 1.4.2.2 bouyer
1519 1.4.2.2 bouyer
1520 1.4.2.2 bouyer /* ARGSUSED */
1521 1.4.2.2 bouyer static int
1522 1.4.2.2 bouyer cmpci_get_props(handle)
1523 1.4.2.2 bouyer void *handle;
1524 1.4.2.2 bouyer {
1525 1.4.2.2 bouyer return AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
1526 1.4.2.2 bouyer }
1527 1.4.2.2 bouyer
1528 1.4.2.2 bouyer
1529 1.4.2.2 bouyer static int
1530 1.4.2.2 bouyer cmpci_trigger_output(handle, start, end, blksize, intr, arg, param)
1531 1.4.2.2 bouyer void *handle;
1532 1.4.2.2 bouyer void *start, *end;
1533 1.4.2.2 bouyer int blksize;
1534 1.4.2.2 bouyer void (*intr) __P((void *));
1535 1.4.2.2 bouyer void *arg;
1536 1.4.2.2 bouyer struct audio_params *param;
1537 1.4.2.2 bouyer {
1538 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1539 1.4.2.2 bouyer struct cmpci_dmanode *p;
1540 1.4.2.2 bouyer int bps;
1541 1.4.2.2 bouyer
1542 1.4.2.2 bouyer sc->sc_play.intr = intr;
1543 1.4.2.2 bouyer sc->sc_play.intr_arg = arg;
1544 1.4.2.2 bouyer bps = param->channels*param->precision*param->factor / 8;
1545 1.4.2.2 bouyer if (!bps)
1546 1.4.2.2 bouyer return EINVAL;
1547 1.4.2.2 bouyer
1548 1.4.2.2 bouyer /* set DMA frame */
1549 1.4.2.2 bouyer if (!(p = cmpci_find_dmamem(sc, start)))
1550 1.4.2.2 bouyer return EINVAL;
1551 1.4.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA0_BASE,
1552 1.4.2.2 bouyer DMAADDR(p));
1553 1.4.2.2 bouyer delay(10);
1554 1.4.2.2 bouyer bus_space_write_2(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA0_BYTES,
1555 1.4.2.2 bouyer ((caddr_t)end - (caddr_t)start + 1) / bps - 1);
1556 1.4.2.2 bouyer delay(10);
1557 1.4.2.2 bouyer
1558 1.4.2.2 bouyer /* set interrupt count */
1559 1.4.2.2 bouyer bus_space_write_2(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA0_SAMPLES,
1560 1.4.2.2 bouyer (blksize + bps - 1) / bps - 1);
1561 1.4.2.2 bouyer delay(10);
1562 1.4.2.2 bouyer
1563 1.4.2.2 bouyer /* start DMA */
1564 1.4.2.2 bouyer cmpci_reg_clear_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH0_DIR); /* PLAY */
1565 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_INTR_CTRL, CMPCI_REG_CH0_INTR_ENABLE);
1566 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH0_ENABLE);
1567 1.4.2.2 bouyer
1568 1.4.2.2 bouyer return 0;
1569 1.4.2.2 bouyer }
1570 1.4.2.2 bouyer
1571 1.4.2.2 bouyer static int
1572 1.4.2.2 bouyer cmpci_trigger_input(handle, start, end, blksize, intr, arg, param)
1573 1.4.2.2 bouyer void *handle;
1574 1.4.2.2 bouyer void *start, *end;
1575 1.4.2.2 bouyer int blksize;
1576 1.4.2.2 bouyer void (*intr) __P((void *));
1577 1.4.2.2 bouyer void *arg;
1578 1.4.2.2 bouyer struct audio_params *param;
1579 1.4.2.2 bouyer {
1580 1.4.2.2 bouyer struct cmpci_softc *sc = handle;
1581 1.4.2.2 bouyer struct cmpci_dmanode *p;
1582 1.4.2.2 bouyer int bps;
1583 1.4.2.2 bouyer
1584 1.4.2.2 bouyer sc->sc_rec.intr = intr;
1585 1.4.2.2 bouyer sc->sc_rec.intr_arg = arg;
1586 1.4.2.2 bouyer bps = param->channels*param->precision*param->factor/8;
1587 1.4.2.2 bouyer if (!bps)
1588 1.4.2.2 bouyer return EINVAL;
1589 1.4.2.2 bouyer
1590 1.4.2.2 bouyer /* set DMA frame */
1591 1.4.2.2 bouyer if (!(p=cmpci_find_dmamem(sc, start)))
1592 1.4.2.2 bouyer return EINVAL;
1593 1.4.2.2 bouyer bus_space_write_4(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA1_BASE,
1594 1.4.2.2 bouyer DMAADDR(p));
1595 1.4.2.2 bouyer delay(10);
1596 1.4.2.2 bouyer bus_space_write_2(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA1_BYTES,
1597 1.4.2.2 bouyer ((caddr_t)end - (caddr_t)start + 1) / bps - 1);
1598 1.4.2.2 bouyer delay(10);
1599 1.4.2.2 bouyer
1600 1.4.2.2 bouyer /* set interrupt count */
1601 1.4.2.2 bouyer bus_space_write_2(sc->sc_iot, sc->sc_ioh, CMPCI_REG_DMA1_SAMPLES,
1602 1.4.2.2 bouyer (blksize + bps - 1) / bps - 1);
1603 1.4.2.2 bouyer delay(10);
1604 1.4.2.2 bouyer
1605 1.4.2.2 bouyer /* start DMA */
1606 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH1_DIR); /* REC */
1607 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_INTR_CTRL, CMPCI_REG_CH1_INTR_ENABLE);
1608 1.4.2.2 bouyer cmpci_reg_set_4(sc, CMPCI_REG_FUNC_0, CMPCI_REG_CH1_ENABLE);
1609 1.4.2.2 bouyer
1610 1.4.2.2 bouyer return 0;
1611 1.4.2.2 bouyer }
1612 1.4.2.2 bouyer
1613 1.4.2.2 bouyer
1614 1.4.2.2 bouyer /* end of file */
1615