awacs.c revision 1.24.20.1 1 1.24.20.1 ad /* $NetBSD: awacs.c,v 1.24.20.1 2007/02/01 08:48:07 ad Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*-
4 1.1 tsubai * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
5 1.1 tsubai *
6 1.1 tsubai * Redistribution and use in source and binary forms, with or without
7 1.1 tsubai * modification, are permitted provided that the following conditions
8 1.1 tsubai * are met:
9 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
10 1.1 tsubai * notice, this list of conditions and the following disclaimer.
11 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
13 1.1 tsubai * documentation and/or other materials provided with the distribution.
14 1.1 tsubai * 3. The name of the author may not be used to endorse or promote products
15 1.1 tsubai * derived from this software without specific prior written permission.
16 1.1 tsubai *
17 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsubai */
28 1.19 lukem
29 1.19 lukem #include <sys/cdefs.h>
30 1.24.20.1 ad __KERNEL_RCSID(0, "$NetBSD: awacs.c,v 1.24.20.1 2007/02/01 08:48:07 ad Exp $");
31 1.1 tsubai
32 1.1 tsubai #include <sys/param.h>
33 1.1 tsubai #include <sys/audioio.h>
34 1.1 tsubai #include <sys/device.h>
35 1.1 tsubai #include <sys/malloc.h>
36 1.1 tsubai #include <sys/systm.h>
37 1.1 tsubai
38 1.1 tsubai #include <dev/auconv.h>
39 1.1 tsubai #include <dev/audio_if.h>
40 1.1 tsubai #include <dev/mulaw.h>
41 1.1 tsubai
42 1.1 tsubai #include <uvm/uvm_extern.h>
43 1.1 tsubai
44 1.1 tsubai #include <machine/autoconf.h>
45 1.1 tsubai #include <machine/pio.h>
46 1.10 matt
47 1.10 matt #include <dev/ofw/openfirm.h>
48 1.1 tsubai #include <macppc/dev/dbdma.h>
49 1.1 tsubai
50 1.24.20.1 ad #include <dev/i2c/sgsmixvar.h>
51 1.24.20.1 ad #include "sgsmix.h"
52 1.24.20.1 ad
53 1.1 tsubai #ifdef AWACS_DEBUG
54 1.1 tsubai # define DPRINTF printf
55 1.1 tsubai #else
56 1.1 tsubai # define DPRINTF while (0) printf
57 1.1 tsubai #endif
58 1.1 tsubai
59 1.9 tsubai /* sc_flags values */
60 1.9 tsubai #define AWACS_CAP_BSWAP 0x0001
61 1.9 tsubai
62 1.1 tsubai struct awacs_softc {
63 1.1 tsubai struct device sc_dev;
64 1.9 tsubai int sc_flags;
65 1.1 tsubai
66 1.18 wiz void (*sc_ointr)(void *); /* DMA completion intr handler */
67 1.1 tsubai void *sc_oarg; /* arg for sc_ointr() */
68 1.1 tsubai int sc_opages; /* # of output pages */
69 1.1 tsubai
70 1.18 wiz void (*sc_iintr)(void *); /* DMA completion intr handler */
71 1.1 tsubai void *sc_iarg; /* arg for sc_iintr() */
72 1.1 tsubai
73 1.1 tsubai u_int sc_record_source; /* recording source mask */
74 1.1 tsubai u_int sc_output_mask; /* output source mask */
75 1.1 tsubai
76 1.24.20.1 ad int sc_screamer;
77 1.24.20.1 ad int sc_have_perch;
78 1.24.20.1 ad int spk_l, spk_r, hph_l, hph_r;
79 1.24.20.1 ad int sc_bass, sc_treble;
80 1.24.20.1 ad #if NSGSMIX > 0
81 1.24.20.1 ad struct device *sc_sgsmix;
82 1.24.20.1 ad #endif
83 1.24.20.1 ad
84 1.1 tsubai char *sc_reg;
85 1.1 tsubai u_int sc_codecctl0;
86 1.1 tsubai u_int sc_codecctl1;
87 1.1 tsubai u_int sc_codecctl2;
88 1.1 tsubai u_int sc_codecctl4;
89 1.24.20.1 ad u_int sc_codecctl5;
90 1.24.20.1 ad u_int sc_codecctl6;
91 1.24.20.1 ad u_int sc_codecctl7;
92 1.1 tsubai u_int sc_soundctl;
93 1.1 tsubai
94 1.1 tsubai struct dbdma_regmap *sc_odma;
95 1.1 tsubai struct dbdma_regmap *sc_idma;
96 1.1 tsubai struct dbdma_command *sc_odmacmd;
97 1.1 tsubai struct dbdma_command *sc_idmacmd;
98 1.22 kent
99 1.22 kent #define AWACS_NFORMATS 2
100 1.22 kent struct audio_format sc_formats[AWACS_NFORMATS];
101 1.1 tsubai };
102 1.1 tsubai
103 1.1 tsubai int awacs_match(struct device *, struct cfdata *, void *);
104 1.1 tsubai void awacs_attach(struct device *, struct device *, void *);
105 1.1 tsubai int awacs_intr(void *);
106 1.1 tsubai
107 1.1 tsubai void awacs_close(void *);
108 1.1 tsubai int awacs_query_encoding(void *, struct audio_encoding *);
109 1.22 kent int awacs_set_params(void *, int, int, audio_params_t *, audio_params_t *,
110 1.23 kent stream_filter_list_t *, stream_filter_list_t *);
111 1.22 kent int awacs_round_blocksize(void *, int, int, const audio_params_t *);
112 1.1 tsubai int awacs_trigger_output(void *, void *, void *, int, void (*)(void *),
113 1.23 kent void *, const audio_params_t *);
114 1.1 tsubai int awacs_trigger_input(void *, void *, void *, int, void (*)(void *),
115 1.23 kent void *, const audio_params_t *);
116 1.1 tsubai int awacs_halt_output(void *);
117 1.1 tsubai int awacs_halt_input(void *);
118 1.1 tsubai int awacs_getdev(void *, struct audio_device *);
119 1.1 tsubai int awacs_set_port(void *, mixer_ctrl_t *);
120 1.1 tsubai int awacs_get_port(void *, mixer_ctrl_t *);
121 1.1 tsubai int awacs_query_devinfo(void *, mixer_devinfo_t *);
122 1.1 tsubai size_t awacs_round_buffersize(void *, int, size_t);
123 1.1 tsubai paddr_t awacs_mappage(void *, void *, off_t, int);
124 1.1 tsubai int awacs_get_props(void *);
125 1.1 tsubai
126 1.1 tsubai static inline u_int awacs_read_reg(struct awacs_softc *, int);
127 1.1 tsubai static inline void awacs_write_reg(struct awacs_softc *, int, int);
128 1.1 tsubai void awacs_write_codec(struct awacs_softc *, int);
129 1.1 tsubai void awacs_set_speaker_volume(struct awacs_softc *, int, int);
130 1.1 tsubai void awacs_set_ext_volume(struct awacs_softc *, int, int);
131 1.24.20.1 ad void awacs_set_loopthrough_volume(struct awacs_softc *, int, int);
132 1.23 kent int awacs_set_rate(struct awacs_softc *, const audio_params_t *);
133 1.24.20.1 ad void awacs_select_output(struct awacs_softc *, int);
134 1.24.20.1 ad #if NSGSMIX > 0
135 1.24.20.1 ad static void awacs_set_bass(struct awacs_softc *, int);
136 1.24.20.1 ad static void awacs_set_treble(struct awacs_softc *, int);
137 1.24.20.1 ad #endif
138 1.24.20.1 ad static int awacs_setup_sgsmix(struct device *);
139 1.1 tsubai
140 1.14 thorpej CFATTACH_DECL(awacs, sizeof(struct awacs_softc),
141 1.14 thorpej awacs_match, awacs_attach, NULL, NULL);
142 1.1 tsubai
143 1.21 yamt const struct audio_hw_if awacs_hw_if = {
144 1.22 kent NULL, /* open */
145 1.1 tsubai awacs_close,
146 1.1 tsubai NULL,
147 1.1 tsubai awacs_query_encoding,
148 1.1 tsubai awacs_set_params,
149 1.1 tsubai awacs_round_blocksize,
150 1.1 tsubai NULL,
151 1.1 tsubai NULL,
152 1.1 tsubai NULL,
153 1.1 tsubai NULL,
154 1.1 tsubai NULL,
155 1.1 tsubai awacs_halt_output,
156 1.1 tsubai awacs_halt_input,
157 1.1 tsubai NULL,
158 1.1 tsubai awacs_getdev,
159 1.1 tsubai NULL,
160 1.1 tsubai awacs_set_port,
161 1.1 tsubai awacs_get_port,
162 1.1 tsubai awacs_query_devinfo,
163 1.1 tsubai NULL,
164 1.1 tsubai NULL,
165 1.1 tsubai awacs_round_buffersize,
166 1.1 tsubai awacs_mappage,
167 1.1 tsubai awacs_get_props,
168 1.1 tsubai awacs_trigger_output,
169 1.1 tsubai awacs_trigger_input,
170 1.12 augustss NULL,
171 1.1 tsubai };
172 1.1 tsubai
173 1.1 tsubai struct audio_device awacs_device = {
174 1.1 tsubai "AWACS",
175 1.1 tsubai "",
176 1.1 tsubai "awacs"
177 1.1 tsubai };
178 1.1 tsubai
179 1.22 kent #define AWACS_NFORMATS 2
180 1.22 kent #define AWACS_FORMATS_LE 0
181 1.22 kent static const struct audio_format awacs_formats[AWACS_NFORMATS] = {
182 1.22 kent {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
183 1.22 kent 2, AUFMT_STEREO, 8, {7350, 8820, 11025, 14700, 17640, 22050, 29400, 44100}},
184 1.22 kent {NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_BE, 16, 16,
185 1.22 kent 2, AUFMT_STEREO, 8, {7350, 8820, 11025, 14700, 17640, 22050, 29400, 44100}},
186 1.22 kent };
187 1.22 kent
188 1.1 tsubai /* register offset */
189 1.1 tsubai #define AWACS_SOUND_CTRL 0x00
190 1.1 tsubai #define AWACS_CODEC_CTRL 0x10
191 1.1 tsubai #define AWACS_CODEC_STATUS 0x20
192 1.1 tsubai #define AWACS_CLIP_COUNT 0x30
193 1.1 tsubai #define AWACS_BYTE_SWAP 0x40
194 1.1 tsubai
195 1.1 tsubai /* sound control */
196 1.1 tsubai #define AWACS_INPUT_SUBFRAME0 0x00000001
197 1.1 tsubai #define AWACS_INPUT_SUBFRAME1 0x00000002
198 1.1 tsubai #define AWACS_INPUT_SUBFRAME2 0x00000004
199 1.1 tsubai #define AWACS_INPUT_SUBFRAME3 0x00000008
200 1.1 tsubai
201 1.1 tsubai #define AWACS_OUTPUT_SUBFRAME0 0x00000010
202 1.1 tsubai #define AWACS_OUTPUT_SUBFRAME1 0x00000020
203 1.1 tsubai #define AWACS_OUTPUT_SUBFRAME2 0x00000040
204 1.1 tsubai #define AWACS_OUTPUT_SUBFRAME3 0x00000080
205 1.1 tsubai
206 1.1 tsubai #define AWACS_RATE_44100 0x00000000
207 1.1 tsubai #define AWACS_RATE_29400 0x00000100
208 1.1 tsubai #define AWACS_RATE_22050 0x00000200
209 1.1 tsubai #define AWACS_RATE_17640 0x00000300
210 1.1 tsubai #define AWACS_RATE_14700 0x00000400
211 1.1 tsubai #define AWACS_RATE_11025 0x00000500
212 1.1 tsubai #define AWACS_RATE_8820 0x00000600
213 1.1 tsubai #define AWACS_RATE_7350 0x00000700
214 1.1 tsubai #define AWACS_RATE_MASK 0x00000700
215 1.1 tsubai
216 1.1 tsubai /* codec control */
217 1.1 tsubai #define AWACS_CODEC_ADDR0 0x00000000
218 1.1 tsubai #define AWACS_CODEC_ADDR1 0x00001000
219 1.1 tsubai #define AWACS_CODEC_ADDR2 0x00002000
220 1.1 tsubai #define AWACS_CODEC_ADDR4 0x00004000
221 1.24.20.1 ad #define AWACS_CODEC_ADDR5 0x00005000
222 1.24.20.1 ad #define AWACS_CODEC_ADDR6 0x00006000
223 1.24.20.1 ad #define AWACS_CODEC_ADDR7 0x00007000
224 1.1 tsubai #define AWACS_CODEC_EMSEL0 0x00000000
225 1.1 tsubai #define AWACS_CODEC_EMSEL1 0x00400000
226 1.1 tsubai #define AWACS_CODEC_EMSEL2 0x00800000
227 1.1 tsubai #define AWACS_CODEC_EMSEL4 0x00c00000
228 1.1 tsubai #define AWACS_CODEC_BUSY 0x01000000
229 1.1 tsubai
230 1.1 tsubai /* cc0 */
231 1.1 tsubai #define AWACS_DEFAULT_CD_GAIN 0x000000bb
232 1.1 tsubai #define AWACS_INPUT_CD 0x00000200
233 1.4 wiz #define AWACS_INPUT_LINE 0x00000400
234 1.4 wiz #define AWACS_INPUT_MICROPHONE 0x00000800
235 1.1 tsubai #define AWACS_INPUT_MASK 0x00000e00
236 1.1 tsubai
237 1.1 tsubai /* cc1 */
238 1.24.20.1 ad #define AWACS_LOOP_THROUGH 0x00000040
239 1.1 tsubai #define AWACS_MUTE_SPEAKER 0x00000080
240 1.1 tsubai #define AWACS_MUTE_HEADPHONE 0x00000200
241 1.24.20.1 ad #define AWACS_PARALLEL_OUTPUT 0x00000c00
242 1.1 tsubai
243 1.24.20.1 ad /* output */
244 1.24.20.1 ad #define OUTPUT_SPEAKER 1
245 1.24.20.1 ad #define OUTPUT_HEADPHONES 2
246 1.1 tsubai int
247 1.23 kent awacs_match(struct device *parent, struct cfdata *match, void *aux)
248 1.1 tsubai {
249 1.23 kent struct confargs *ca;
250 1.1 tsubai
251 1.23 kent ca = aux;
252 1.16 soren if (strcmp(ca->ca_name, "i2s") == 0)
253 1.16 soren return 1;
254 1.16 soren
255 1.1 tsubai if (strcmp(ca->ca_name, "awacs") != 0 &&
256 1.1 tsubai strcmp(ca->ca_name, "davbus") != 0)
257 1.1 tsubai return 0;
258 1.1 tsubai
259 1.1 tsubai if (ca->ca_nreg < 24 || ca->ca_nintr < 12)
260 1.2 tsubai return 0;
261 1.2 tsubai
262 1.1 tsubai return 1;
263 1.1 tsubai }
264 1.1 tsubai
265 1.1 tsubai void
266 1.23 kent awacs_attach(struct device *parent, struct device *self, void *aux)
267 1.1 tsubai {
268 1.23 kent struct awacs_softc *sc;
269 1.23 kent struct confargs *ca;
270 1.9 tsubai int cirq, oirq, iirq, cirq_type, oirq_type, iirq_type;
271 1.24.20.1 ad int len = -1, perch;
272 1.24.20.1 ad char compat[255];
273 1.23 kent
274 1.23 kent sc = (struct awacs_softc *)self;
275 1.23 kent ca = aux;
276 1.1 tsubai
277 1.24.20.1 ad sc->sc_reg = mapiodev(ca->ca_baseaddr + ca->ca_reg[0], ca->ca_reg[1]);
278 1.1 tsubai
279 1.24.20.1 ad /* out */
280 1.24.20.1 ad sc->sc_odma = mapiodev(ca->ca_baseaddr + ca->ca_reg[2], ca->ca_reg[3]);
281 1.1 tsubai sc->sc_odmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
282 1.24.20.1 ad /* in */
283 1.24.20.1 ad sc->sc_idma = mapiodev(ca->ca_baseaddr + ca->ca_reg[4], ca->ca_reg[5]);
284 1.1 tsubai sc->sc_idmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
285 1.1 tsubai
286 1.24.20.1 ad aprint_debug("base: %08x reg: %08x %08x %08x\n",ca->ca_baseaddr,
287 1.24.20.1 ad ca->ca_reg[0], ca->ca_reg[2], ca->ca_reg[4]);
288 1.24.20.1 ad
289 1.16 soren if (strcmp(ca->ca_name, "i2s") == 0) {
290 1.16 soren int node, intr[6];
291 1.16 soren
292 1.16 soren node = OF_child(ca->ca_node);
293 1.20 thorpej if (node == 0) {
294 1.16 soren printf("no i2s-a child\n");
295 1.16 soren return;
296 1.16 soren }
297 1.16 soren if (OF_getprop(node, "interrupts", intr, sizeof(intr)) == -1) {
298 1.16 soren printf("no interrupt property\n");
299 1.16 soren return;
300 1.16 soren }
301 1.16 soren
302 1.16 soren cirq = intr[0];
303 1.16 soren oirq = intr[2];
304 1.16 soren iirq = intr[4];
305 1.16 soren cirq_type = intr[1] ? IST_LEVEL : IST_EDGE;
306 1.16 soren oirq_type = intr[3] ? IST_LEVEL : IST_EDGE;
307 1.16 soren iirq_type = intr[5] ? IST_LEVEL : IST_EDGE;
308 1.16 soren } else if (ca->ca_nintr == 24) {
309 1.9 tsubai cirq = ca->ca_intr[0];
310 1.9 tsubai oirq = ca->ca_intr[2];
311 1.9 tsubai iirq = ca->ca_intr[4];
312 1.9 tsubai cirq_type = ca->ca_intr[1] ? IST_LEVEL : IST_EDGE;
313 1.9 tsubai oirq_type = ca->ca_intr[3] ? IST_LEVEL : IST_EDGE;
314 1.9 tsubai iirq_type = ca->ca_intr[5] ? IST_LEVEL : IST_EDGE;
315 1.9 tsubai } else {
316 1.9 tsubai cirq = ca->ca_intr[0];
317 1.9 tsubai oirq = ca->ca_intr[1];
318 1.9 tsubai iirq = ca->ca_intr[2];
319 1.9 tsubai cirq_type = oirq_type = iirq_type = IST_LEVEL;
320 1.9 tsubai }
321 1.16 soren
322 1.9 tsubai intr_establish(cirq, cirq_type, IPL_AUDIO, awacs_intr, sc);
323 1.9 tsubai intr_establish(oirq, oirq_type, IPL_AUDIO, awacs_intr, sc);
324 1.24.20.1 ad intr_establish(iirq, iirq_type, IPL_AUDIO, awacs_intr, sc);
325 1.24.20.1 ad
326 1.24.20.1 ad /* check if the chip is a screamer */
327 1.24.20.1 ad sc->sc_screamer = 0;
328 1.24.20.1 ad memset(compat, 0, 256);
329 1.24.20.1 ad if ((len = OF_getprop(ca->ca_node, "compatible", compat, 255)) <= 0) {
330 1.24.20.1 ad int child;
331 1.24.20.1 ad
332 1.24.20.1 ad child = OF_child(ca->ca_node);
333 1.24.20.1 ad while ((child != -1) && (len <= 0)) {
334 1.24.20.1 ad len = OF_getprop(child, "compatible", compat, 255);
335 1.24.20.1 ad child = OF_peer(child);
336 1.24.20.1 ad }
337 1.24.20.1 ad }
338 1.24.20.1 ad if (len > 0) {
339 1.24.20.1 ad char *ptr = compat;
340 1.24.20.1 ad
341 1.24.20.1 ad while (( ptr[0] != 0) && (sc->sc_screamer == 0)) {
342 1.24.20.1 ad sc->sc_screamer = (strcmp(ptr, "screamer") == 0);
343 1.24.20.1 ad ptr += strlen(ptr) + 1;
344 1.24.20.1 ad }
345 1.24.20.1 ad }
346 1.24.20.1 ad if (sc->sc_screamer)
347 1.24.20.1 ad printf(" Screamer");
348 1.24.20.1 ad
349 1.9 tsubai
350 1.9 tsubai printf(": irq %d,%d,%d\n", cirq, oirq, iirq);
351 1.9 tsubai
352 1.24.20.1 ad sc->spk_l = 0;
353 1.24.20.1 ad sc->spk_r = 0;
354 1.24.20.1 ad sc->hph_l = 0;
355 1.24.20.1 ad sc->hph_r = 0;
356 1.24.20.1 ad
357 1.22 kent memcpy(&sc->sc_formats, awacs_formats, sizeof(awacs_formats));
358 1.9 tsubai /* XXX Uni-North based models don't have byteswap capability. */
359 1.22 kent if (OF_finddevice("/uni-n") == -1) {
360 1.9 tsubai sc->sc_flags |= AWACS_CAP_BSWAP;
361 1.22 kent } else {
362 1.22 kent AUFMT_INVALIDATE(&sc->sc_formats[AWACS_FORMATS_LE]);
363 1.22 kent }
364 1.1 tsubai
365 1.1 tsubai sc->sc_soundctl = AWACS_INPUT_SUBFRAME0 | AWACS_OUTPUT_SUBFRAME0 |
366 1.1 tsubai AWACS_RATE_44100;
367 1.1 tsubai awacs_write_reg(sc, AWACS_SOUND_CTRL, sc->sc_soundctl);
368 1.1 tsubai
369 1.1 tsubai sc->sc_codecctl0 = AWACS_CODEC_ADDR0 | AWACS_CODEC_EMSEL0;
370 1.1 tsubai sc->sc_codecctl1 = AWACS_CODEC_ADDR1 | AWACS_CODEC_EMSEL0;
371 1.1 tsubai sc->sc_codecctl2 = AWACS_CODEC_ADDR2 | AWACS_CODEC_EMSEL0;
372 1.1 tsubai sc->sc_codecctl4 = AWACS_CODEC_ADDR4 | AWACS_CODEC_EMSEL0;
373 1.24.20.1 ad sc->sc_codecctl5 = AWACS_CODEC_ADDR5 | AWACS_CODEC_EMSEL0;
374 1.24.20.1 ad sc->sc_codecctl6 = AWACS_CODEC_ADDR6 | AWACS_CODEC_EMSEL0;
375 1.24.20.1 ad sc->sc_codecctl7 = AWACS_CODEC_ADDR7 | AWACS_CODEC_EMSEL0;
376 1.1 tsubai
377 1.1 tsubai sc->sc_codecctl0 |= AWACS_INPUT_CD | AWACS_DEFAULT_CD_GAIN;
378 1.1 tsubai awacs_write_codec(sc, sc->sc_codecctl0);
379 1.1 tsubai
380 1.1 tsubai /* Set loopback (for CD?) */
381 1.4 wiz /* sc->sc_codecctl1 |= 0x440; */
382 1.24.20.1 ad sc->sc_codecctl1 |= (AWACS_LOOP_THROUGH | AWACS_PARALLEL_OUTPUT);
383 1.1 tsubai
384 1.24.20.1 ad /* check for headphone present */
385 1.24.20.1 ad if (awacs_read_reg(sc, AWACS_CODEC_STATUS) & 0x8) {
386 1.24.20.1 ad /* default output to speakers */
387 1.24.20.1 ad printf(" headphones");
388 1.24.20.1 ad sc->sc_output_mask = OUTPUT_HEADPHONES;
389 1.24.20.1 ad sc->sc_codecctl1 &= ~AWACS_MUTE_HEADPHONE;
390 1.24.20.1 ad sc->sc_codecctl1 |= AWACS_MUTE_SPEAKER;
391 1.24.20.1 ad } else {
392 1.24.20.1 ad /* default output to speakers */
393 1.24.20.1 ad printf(" speaker");
394 1.24.20.1 ad sc->sc_output_mask = OUTPUT_SPEAKER;
395 1.24.20.1 ad sc->sc_codecctl1 &= ~AWACS_MUTE_SPEAKER;
396 1.24.20.1 ad sc->sc_codecctl1 |= AWACS_MUTE_HEADPHONE;
397 1.24.20.1 ad }
398 1.1 tsubai awacs_write_codec(sc, sc->sc_codecctl1);
399 1.1 tsubai
400 1.24.20.1 ad delay(100);
401 1.24.20.1 ad if (sc->sc_screamer) {
402 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl6);
403 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl5);
404 1.24.20.1 ad delay(2);
405 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl1);
406 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl7);
407 1.24.20.1 ad }
408 1.24.20.1 ad
409 1.4 wiz /* default input from CD */
410 1.4 wiz sc->sc_record_source = 1 << 0;
411 1.4 wiz sc->sc_codecctl0 &= ~AWACS_INPUT_MASK;
412 1.4 wiz sc->sc_codecctl0 |= AWACS_INPUT_CD;
413 1.4 wiz awacs_write_codec(sc, sc->sc_codecctl0);
414 1.4 wiz
415 1.1 tsubai /* Enable interrupts and looping mode. */
416 1.1 tsubai /* XXX ... */
417 1.1 tsubai
418 1.24.20.1 ad sc->sc_codecctl1 |= (AWACS_LOOP_THROUGH | AWACS_PARALLEL_OUTPUT);
419 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl1);
420 1.24.20.1 ad
421 1.24.20.1 ad #if NSGSMIX > 0
422 1.24.20.1 ad sc->sc_sgsmix = NULL;
423 1.24.20.1 ad #endif
424 1.24.20.1 ad sc->sc_have_perch = 0;
425 1.24.20.1 ad if ((perch = OF_finddevice("/perch")) != -1) {
426 1.24.20.1 ad
427 1.24.20.1 ad len = OF_getprop(perch, "compatible", compat, 255);
428 1.24.20.1 ad if (len > 0) {
429 1.24.20.1 ad printf("%s: found '%s' personality card\n",
430 1.24.20.1 ad sc->sc_dev.dv_xname, compat);
431 1.24.20.1 ad sc->sc_have_perch = 1;
432 1.24.20.1 ad config_finalize_register(&sc->sc_dev, awacs_setup_sgsmix);
433 1.24.20.1 ad }
434 1.24.20.1 ad }
435 1.24.20.1 ad
436 1.24.20.1 ad /* Set initial volume[s] */
437 1.24.20.1 ad awacs_set_speaker_volume(sc, 80, 80);
438 1.24.20.1 ad awacs_set_ext_volume(sc, 120, 120);
439 1.24.20.1 ad //awacs_set_loopthrough_volume(sc, 240, 240);
440 1.24.20.1 ad
441 1.1 tsubai audio_attach_mi(&awacs_hw_if, sc, &sc->sc_dev);
442 1.1 tsubai }
443 1.1 tsubai
444 1.24.20.1 ad static int
445 1.24.20.1 ad awacs_setup_sgsmix(struct device *cookie)
446 1.24.20.1 ad {
447 1.24.20.1 ad struct awacs_softc *sc = (struct awacs_softc *)cookie;
448 1.24.20.1 ad #if NSGSMIX > 0
449 1.24.20.1 ad struct device *dv;
450 1.24.20.1 ad #endif
451 1.24.20.1 ad
452 1.24.20.1 ad if (!sc->sc_have_perch)
453 1.24.20.1 ad return 0;
454 1.24.20.1 ad #if NSGSMIX > 0
455 1.24.20.1 ad /* look for sgsmix */
456 1.24.20.1 ad for (dv = alldevs.tqh_first; dv; dv=dv->dv_list.tqe_next) {
457 1.24.20.1 ad if (device_is_a(dv, "sgsmix")) {
458 1.24.20.1 ad sc->sc_sgsmix = dv;
459 1.24.20.1 ad break;
460 1.24.20.1 ad }
461 1.24.20.1 ad }
462 1.24.20.1 ad if (sc->sc_sgsmix == NULL)
463 1.24.20.1 ad return 0;
464 1.24.20.1 ad
465 1.24.20.1 ad printf("%s: using %s\n", sc->sc_dev.dv_xname,
466 1.24.20.1 ad sc->sc_sgsmix->dv_xname);
467 1.24.20.1 ad
468 1.24.20.1 ad awacs_select_output(sc, sc->sc_output_mask);
469 1.24.20.1 ad awacs_set_speaker_volume(sc, sc->spk_l, sc->spk_r);
470 1.24.20.1 ad awacs_set_ext_volume(sc, sc->hph_l, sc->hph_r);
471 1.24.20.1 ad awacs_set_bass(sc, 128);
472 1.24.20.1 ad awacs_set_treble(sc, 128);
473 1.24.20.1 ad #endif
474 1.24.20.1 ad return 0;
475 1.24.20.1 ad }
476 1.24.20.1 ad
477 1.24.20.1 ad
478 1.11 simonb static inline u_int
479 1.23 kent awacs_read_reg(struct awacs_softc *sc, int reg)
480 1.1 tsubai {
481 1.23 kent char *addr;
482 1.1 tsubai
483 1.23 kent addr = sc->sc_reg;
484 1.1 tsubai return in32rb(addr + reg);
485 1.1 tsubai }
486 1.1 tsubai
487 1.11 simonb static inline void
488 1.23 kent awacs_write_reg(struct awacs_softc *sc, int reg, int val)
489 1.1 tsubai {
490 1.23 kent char *addr;
491 1.1 tsubai
492 1.23 kent addr = sc->sc_reg;
493 1.1 tsubai out32rb(addr + reg, val);
494 1.1 tsubai }
495 1.1 tsubai
496 1.1 tsubai void
497 1.23 kent awacs_write_codec(struct awacs_softc *sc, int value)
498 1.1 tsubai {
499 1.23 kent
500 1.24.20.1 ad do {
501 1.24.20.1 ad delay(100);
502 1.24.20.1 ad } while (awacs_read_reg(sc, AWACS_CODEC_CTRL) & AWACS_CODEC_BUSY);
503 1.24.20.1 ad
504 1.1 tsubai awacs_write_reg(sc, AWACS_CODEC_CTRL, value);
505 1.24.20.1 ad
506 1.24.20.1 ad do {
507 1.24.20.1 ad delay(100);
508 1.24.20.1 ad } while (awacs_read_reg(sc, AWACS_CODEC_CTRL) & AWACS_CODEC_BUSY);
509 1.1 tsubai }
510 1.1 tsubai
511 1.1 tsubai int
512 1.23 kent awacs_intr(void *v)
513 1.1 tsubai {
514 1.23 kent struct awacs_softc *sc;
515 1.23 kent struct dbdma_command *cmd;
516 1.23 kent int count;
517 1.1 tsubai int status;
518 1.1 tsubai
519 1.23 kent sc = v;
520 1.23 kent cmd = sc->sc_odmacmd;
521 1.23 kent count = sc->sc_opages;
522 1.1 tsubai /* Fill used buffer(s). */
523 1.1 tsubai while (count-- > 0) {
524 1.1 tsubai /* if DBDMA_INT_ALWAYS */
525 1.1 tsubai if (in16rb(&cmd->d_command) & 0x30) { /* XXX */
526 1.1 tsubai status = in16rb(&cmd->d_status);
527 1.1 tsubai cmd->d_status = 0;
528 1.1 tsubai if (status) /* status == 0x8400 */
529 1.1 tsubai if (sc->sc_ointr)
530 1.1 tsubai (*sc->sc_ointr)(sc->sc_oarg);
531 1.1 tsubai }
532 1.1 tsubai cmd++;
533 1.1 tsubai }
534 1.1 tsubai
535 1.1 tsubai return 1;
536 1.1 tsubai }
537 1.1 tsubai
538 1.1 tsubai /*
539 1.1 tsubai * Close function is called at splaudio().
540 1.1 tsubai */
541 1.1 tsubai void
542 1.23 kent awacs_close(void *h)
543 1.1 tsubai {
544 1.23 kent struct awacs_softc *sc;
545 1.1 tsubai
546 1.23 kent sc = h;
547 1.1 tsubai awacs_halt_output(sc);
548 1.1 tsubai awacs_halt_input(sc);
549 1.1 tsubai
550 1.1 tsubai sc->sc_ointr = 0;
551 1.1 tsubai sc->sc_iintr = 0;
552 1.1 tsubai }
553 1.1 tsubai
554 1.1 tsubai int
555 1.23 kent awacs_query_encoding(void *h, struct audio_encoding *ae)
556 1.1 tsubai {
557 1.23 kent struct awacs_softc *sc;
558 1.9 tsubai
559 1.23 kent sc = h;
560 1.9 tsubai ae->flags = AUDIO_ENCODINGFLAG_EMULATED;
561 1.9 tsubai
562 1.1 tsubai switch (ae->index) {
563 1.1 tsubai case 0:
564 1.1 tsubai strcpy(ae->name, AudioEslinear);
565 1.1 tsubai ae->encoding = AUDIO_ENCODING_SLINEAR;
566 1.1 tsubai ae->precision = 16;
567 1.1 tsubai ae->flags = 0;
568 1.1 tsubai return 0;
569 1.1 tsubai case 1:
570 1.1 tsubai strcpy(ae->name, AudioEslinear_be);
571 1.1 tsubai ae->encoding = AUDIO_ENCODING_SLINEAR_BE;
572 1.1 tsubai ae->precision = 16;
573 1.1 tsubai ae->flags = 0;
574 1.1 tsubai return 0;
575 1.1 tsubai case 2:
576 1.1 tsubai strcpy(ae->name, AudioEslinear_le);
577 1.1 tsubai ae->encoding = AUDIO_ENCODING_SLINEAR_LE;
578 1.1 tsubai ae->precision = 16;
579 1.9 tsubai if (sc->sc_flags & AWACS_CAP_BSWAP)
580 1.9 tsubai ae->flags = 0;
581 1.1 tsubai return 0;
582 1.1 tsubai case 3:
583 1.6 tsubai strcpy(ae->name, AudioEulinear_be);
584 1.6 tsubai ae->encoding = AUDIO_ENCODING_ULINEAR_BE;
585 1.6 tsubai ae->precision = 16;
586 1.6 tsubai return 0;
587 1.6 tsubai case 4:
588 1.6 tsubai strcpy(ae->name, AudioEulinear_le);
589 1.6 tsubai ae->encoding = AUDIO_ENCODING_ULINEAR_LE;
590 1.6 tsubai ae->precision = 16;
591 1.6 tsubai return 0;
592 1.6 tsubai case 5:
593 1.1 tsubai strcpy(ae->name, AudioEmulaw);
594 1.1 tsubai ae->encoding = AUDIO_ENCODING_ULAW;
595 1.1 tsubai ae->precision = 8;
596 1.1 tsubai return 0;
597 1.6 tsubai case 6:
598 1.1 tsubai strcpy(ae->name, AudioEalaw);
599 1.1 tsubai ae->encoding = AUDIO_ENCODING_ALAW;
600 1.1 tsubai ae->precision = 8;
601 1.1 tsubai return 0;
602 1.1 tsubai default:
603 1.1 tsubai return EINVAL;
604 1.1 tsubai }
605 1.1 tsubai }
606 1.1 tsubai
607 1.1 tsubai int
608 1.23 kent awacs_set_params(void *h, int setmode, int usemode,
609 1.23 kent audio_params_t *play, audio_params_t *rec,
610 1.23 kent stream_filter_list_t *pfil, stream_filter_list_t *rfil)
611 1.1 tsubai {
612 1.23 kent struct awacs_softc *sc;
613 1.23 kent audio_params_t *p;
614 1.22 kent stream_filter_list_t *fil;
615 1.22 kent int mode, i;
616 1.1 tsubai
617 1.23 kent sc = h;
618 1.23 kent p = NULL;
619 1.1 tsubai /*
620 1.1 tsubai * This device only has one clock, so make the sample rates match.
621 1.1 tsubai */
622 1.1 tsubai if (play->sample_rate != rec->sample_rate &&
623 1.1 tsubai usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
624 1.1 tsubai if (setmode == AUMODE_PLAY) {
625 1.1 tsubai rec->sample_rate = play->sample_rate;
626 1.1 tsubai setmode |= AUMODE_RECORD;
627 1.1 tsubai } else if (setmode == AUMODE_RECORD) {
628 1.1 tsubai play->sample_rate = rec->sample_rate;
629 1.1 tsubai setmode |= AUMODE_PLAY;
630 1.1 tsubai } else
631 1.1 tsubai return EINVAL;
632 1.1 tsubai }
633 1.1 tsubai
634 1.1 tsubai for (mode = AUMODE_RECORD; mode != -1;
635 1.1 tsubai mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
636 1.1 tsubai if ((setmode & mode) == 0)
637 1.1 tsubai continue;
638 1.1 tsubai
639 1.1 tsubai p = mode == AUMODE_PLAY ? play : rec;
640 1.22 kent fil = mode == AUMODE_PLAY ? pfil : rfil;
641 1.22 kent switch (p->sample_rate) {
642 1.22 kent case 48000: /* aurateconv */
643 1.22 kent case 44100:
644 1.22 kent case 29400:
645 1.22 kent case 22050:
646 1.22 kent case 17640:
647 1.22 kent case 14700:
648 1.22 kent case 11025:
649 1.22 kent case 8820:
650 1.22 kent case 8000: /* aurateconv */
651 1.22 kent case 7350:
652 1.22 kent break;
653 1.22 kent default:
654 1.1 tsubai return EINVAL;
655 1.22 kent }
656 1.1 tsubai awacs_write_reg(sc, AWACS_BYTE_SWAP, 0);
657 1.22 kent i = auconv_set_converter(sc->sc_formats, AWACS_NFORMATS,
658 1.22 kent mode, p, TRUE, fil);
659 1.22 kent if (i < 0)
660 1.9 tsubai return EINVAL;
661 1.22 kent if (i == AWACS_FORMATS_LE)
662 1.22 kent awacs_write_reg(sc, AWACS_BYTE_SWAP, 1);
663 1.22 kent if (fil->req_size > 0)
664 1.22 kent p = &fil->filters[0].param;
665 1.22 kent if (awacs_set_rate(sc, p))
666 1.1 tsubai return EINVAL;
667 1.1 tsubai }
668 1.1 tsubai return 0;
669 1.1 tsubai }
670 1.1 tsubai
671 1.1 tsubai int
672 1.23 kent awacs_round_blocksize(void *h, int size, int mode, const audio_params_t *param)
673 1.1 tsubai {
674 1.23 kent
675 1.17 thorpej if (size < PAGE_SIZE)
676 1.17 thorpej size = PAGE_SIZE;
677 1.1 tsubai return size & ~PGOFSET;
678 1.1 tsubai }
679 1.1 tsubai
680 1.1 tsubai int
681 1.23 kent awacs_halt_output(void *h)
682 1.1 tsubai {
683 1.23 kent struct awacs_softc *sc;
684 1.1 tsubai
685 1.23 kent sc = h;
686 1.1 tsubai dbdma_stop(sc->sc_odma);
687 1.1 tsubai dbdma_reset(sc->sc_odma);
688 1.1 tsubai return 0;
689 1.1 tsubai }
690 1.1 tsubai
691 1.1 tsubai int
692 1.23 kent awacs_halt_input(void *h)
693 1.1 tsubai {
694 1.23 kent struct awacs_softc *sc;
695 1.1 tsubai
696 1.23 kent sc = h;
697 1.1 tsubai dbdma_stop(sc->sc_idma);
698 1.1 tsubai dbdma_reset(sc->sc_idma);
699 1.1 tsubai return 0;
700 1.1 tsubai }
701 1.1 tsubai
702 1.1 tsubai int
703 1.23 kent awacs_getdev(void *h, struct audio_device *retp)
704 1.1 tsubai {
705 1.23 kent
706 1.1 tsubai *retp = awacs_device;
707 1.1 tsubai return 0;
708 1.1 tsubai }
709 1.1 tsubai
710 1.1 tsubai enum {
711 1.8 tsubai AWACS_MONITOR_CLASS,
712 1.8 tsubai AWACS_OUTPUT_CLASS,
713 1.8 tsubai AWACS_RECORD_CLASS,
714 1.1 tsubai AWACS_OUTPUT_SELECT,
715 1.1 tsubai AWACS_VOL_SPEAKER,
716 1.1 tsubai AWACS_VOL_HEADPHONE,
717 1.4 wiz AWACS_INPUT_SELECT,
718 1.4 wiz AWACS_VOL_INPUT,
719 1.24.20.1 ad AWACS_BASS,
720 1.24.20.1 ad AWACS_TREBLE,
721 1.1 tsubai AWACS_ENUM_LAST
722 1.1 tsubai };
723 1.1 tsubai
724 1.1 tsubai int
725 1.23 kent awacs_set_port(void *h, mixer_ctrl_t *mc)
726 1.1 tsubai {
727 1.23 kent struct awacs_softc *sc;
728 1.1 tsubai int l, r;
729 1.1 tsubai
730 1.1 tsubai DPRINTF("awacs_set_port dev = %d, type = %d\n", mc->dev, mc->type);
731 1.23 kent sc = h;
732 1.1 tsubai l = mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
733 1.1 tsubai r = mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
734 1.1 tsubai
735 1.1 tsubai switch (mc->dev) {
736 1.1 tsubai case AWACS_OUTPUT_SELECT:
737 1.8 tsubai /* No change necessary? */
738 1.3 wiz if (mc->un.mask == sc->sc_output_mask)
739 1.3 wiz return 0;
740 1.24.20.1 ad awacs_select_output(sc, mc->un.mask);
741 1.1 tsubai return 0;
742 1.1 tsubai
743 1.1 tsubai case AWACS_VOL_SPEAKER:
744 1.1 tsubai awacs_set_speaker_volume(sc, l, r);
745 1.1 tsubai return 0;
746 1.1 tsubai
747 1.1 tsubai case AWACS_VOL_HEADPHONE:
748 1.1 tsubai awacs_set_ext_volume(sc, l, r);
749 1.1 tsubai return 0;
750 1.4 wiz
751 1.4 wiz case AWACS_INPUT_SELECT:
752 1.4 wiz /* no change necessary? */
753 1.4 wiz if (mc->un.mask == sc->sc_record_source)
754 1.4 wiz return 0;
755 1.8 tsubai switch (mc->un.mask) {
756 1.8 tsubai case 1 << 0: /* CD */
757 1.4 wiz sc->sc_codecctl0 &= ~AWACS_INPUT_MASK;
758 1.4 wiz sc->sc_codecctl0 |= AWACS_INPUT_CD;
759 1.4 wiz awacs_write_codec(sc, sc->sc_codecctl0);
760 1.4 wiz break;
761 1.8 tsubai case 1 << 1: /* microphone */
762 1.4 wiz sc->sc_codecctl0 &= ~AWACS_INPUT_MASK;
763 1.4 wiz sc->sc_codecctl0 |= AWACS_INPUT_MICROPHONE;
764 1.4 wiz awacs_write_codec(sc, sc->sc_codecctl0);
765 1.4 wiz break;
766 1.8 tsubai case 1 << 2: /* line in */
767 1.4 wiz sc->sc_codecctl0 &= ~AWACS_INPUT_MASK;
768 1.4 wiz sc->sc_codecctl0 |= AWACS_INPUT_LINE;
769 1.4 wiz awacs_write_codec(sc, sc->sc_codecctl0);
770 1.4 wiz break;
771 1.4 wiz default: /* invalid argument */
772 1.8 tsubai return EINVAL;
773 1.4 wiz }
774 1.4 wiz sc->sc_record_source = mc->un.mask;
775 1.4 wiz return 0;
776 1.8 tsubai
777 1.8 tsubai case AWACS_VOL_INPUT:
778 1.8 tsubai sc->sc_codecctl0 &= ~0xff;
779 1.8 tsubai sc->sc_codecctl0 |= (l & 0xf0) | (r >> 4);
780 1.8 tsubai awacs_write_codec(sc, sc->sc_codecctl0);
781 1.8 tsubai return 0;
782 1.24.20.1 ad
783 1.24.20.1 ad #if NSGSMIX > 0
784 1.24.20.1 ad case AWACS_BASS:
785 1.24.20.1 ad awacs_set_bass(sc, l);
786 1.24.20.1 ad return 0;
787 1.24.20.1 ad
788 1.24.20.1 ad case AWACS_TREBLE:
789 1.24.20.1 ad awacs_set_treble(sc, l);
790 1.24.20.1 ad return 0;
791 1.24.20.1 ad #endif
792 1.1 tsubai }
793 1.1 tsubai
794 1.1 tsubai return ENXIO;
795 1.1 tsubai }
796 1.1 tsubai
797 1.1 tsubai int
798 1.23 kent awacs_get_port(void *h, mixer_ctrl_t *mc)
799 1.1 tsubai {
800 1.23 kent struct awacs_softc *sc;
801 1.24.20.1 ad int l, r, vol;
802 1.1 tsubai
803 1.1 tsubai DPRINTF("awacs_get_port dev = %d, type = %d\n", mc->dev, mc->type);
804 1.23 kent sc = h;
805 1.1 tsubai switch (mc->dev) {
806 1.1 tsubai case AWACS_OUTPUT_SELECT:
807 1.1 tsubai mc->un.mask = sc->sc_output_mask;
808 1.1 tsubai return 0;
809 1.1 tsubai
810 1.1 tsubai case AWACS_VOL_SPEAKER:
811 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->spk_l;
812 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->spk_r;
813 1.1 tsubai return 0;
814 1.1 tsubai
815 1.1 tsubai case AWACS_VOL_HEADPHONE:
816 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->hph_l;
817 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->hph_r;
818 1.4 wiz return 0;
819 1.4 wiz
820 1.4 wiz case AWACS_INPUT_SELECT:
821 1.4 wiz mc->un.mask = sc->sc_record_source;
822 1.4 wiz return 0;
823 1.4 wiz
824 1.4 wiz case AWACS_VOL_INPUT:
825 1.4 wiz vol = sc->sc_codecctl0 & 0xff;
826 1.4 wiz l = (vol & 0xf0);
827 1.4 wiz r = (vol & 0x0f) << 4;
828 1.1 tsubai mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
829 1.1 tsubai mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
830 1.1 tsubai return 0;
831 1.24.20.1 ad #if NSGSMIX > 0
832 1.24.20.1 ad case AWACS_BASS:
833 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_bass;
834 1.24.20.1 ad return 0;
835 1.24.20.1 ad
836 1.24.20.1 ad case AWACS_TREBLE:
837 1.24.20.1 ad mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_treble;
838 1.24.20.1 ad return 0;
839 1.24.20.1 ad #endif
840 1.1 tsubai
841 1.1 tsubai default:
842 1.1 tsubai return ENXIO;
843 1.1 tsubai }
844 1.1 tsubai
845 1.1 tsubai return 0;
846 1.1 tsubai }
847 1.1 tsubai
848 1.1 tsubai int
849 1.23 kent awacs_query_devinfo(void *h, mixer_devinfo_t *dip)
850 1.1 tsubai {
851 1.24.20.1 ad #if NSGSMIX > 0
852 1.24.20.1 ad struct awacs_softc *sc = h;
853 1.24.20.1 ad #endif
854 1.1 tsubai
855 1.1 tsubai DPRINTF("query_devinfo %d\n", dip->index);
856 1.1 tsubai
857 1.1 tsubai switch (dip->index) {
858 1.1 tsubai
859 1.1 tsubai case AWACS_OUTPUT_SELECT:
860 1.1 tsubai dip->mixer_class = AWACS_MONITOR_CLASS;
861 1.1 tsubai strcpy(dip->label.name, AudioNoutput);
862 1.1 tsubai dip->type = AUDIO_MIXER_SET;
863 1.1 tsubai dip->prev = dip->next = AUDIO_MIXER_LAST;
864 1.1 tsubai dip->un.s.num_mem = 2;
865 1.1 tsubai strcpy(dip->un.s.member[0].label.name, AudioNspeaker);
866 1.1 tsubai dip->un.s.member[0].mask = 1 << 0;
867 1.1 tsubai strcpy(dip->un.s.member[1].label.name, AudioNheadphone);
868 1.1 tsubai dip->un.s.member[1].mask = 1 << 1;
869 1.1 tsubai return 0;
870 1.1 tsubai
871 1.1 tsubai case AWACS_VOL_SPEAKER:
872 1.1 tsubai dip->mixer_class = AWACS_OUTPUT_CLASS;
873 1.1 tsubai strcpy(dip->label.name, AudioNspeaker);
874 1.1 tsubai dip->type = AUDIO_MIXER_VALUE;
875 1.1 tsubai dip->prev = dip->next = AUDIO_MIXER_LAST;
876 1.1 tsubai dip->un.v.num_channels = 2;
877 1.1 tsubai strcpy(dip->un.v.units.name, AudioNvolume);
878 1.1 tsubai return 0;
879 1.1 tsubai
880 1.1 tsubai case AWACS_VOL_HEADPHONE:
881 1.1 tsubai dip->mixer_class = AWACS_OUTPUT_CLASS;
882 1.1 tsubai strcpy(dip->label.name, AudioNheadphone);
883 1.1 tsubai dip->type = AUDIO_MIXER_VALUE;
884 1.1 tsubai dip->prev = dip->next = AUDIO_MIXER_LAST;
885 1.1 tsubai dip->un.v.num_channels = 2;
886 1.1 tsubai strcpy(dip->un.v.units.name, AudioNvolume);
887 1.1 tsubai return 0;
888 1.1 tsubai
889 1.24.20.1 ad #if NSGSMIX > 0
890 1.24.20.1 ad case AWACS_BASS:
891 1.24.20.1 ad if (sc->sc_sgsmix == NULL)
892 1.24.20.1 ad return ENXIO;
893 1.24.20.1 ad dip->mixer_class = AWACS_MONITOR_CLASS;
894 1.24.20.1 ad strcpy(dip->label.name, AudioNbass);
895 1.24.20.1 ad dip->type = AUDIO_MIXER_VALUE;
896 1.24.20.1 ad dip->prev = dip->next = AUDIO_MIXER_LAST;
897 1.24.20.1 ad dip->un.v.num_channels = 1;
898 1.24.20.1 ad strcpy(dip->un.v.units.name, AudioNbass);
899 1.24.20.1 ad return 0;
900 1.24.20.1 ad
901 1.24.20.1 ad case AWACS_TREBLE:
902 1.24.20.1 ad if (sc->sc_sgsmix == NULL)
903 1.24.20.1 ad return ENXIO;
904 1.24.20.1 ad dip->mixer_class = AWACS_MONITOR_CLASS;
905 1.24.20.1 ad strcpy(dip->label.name, AudioNtreble);
906 1.24.20.1 ad dip->type = AUDIO_MIXER_VALUE;
907 1.24.20.1 ad dip->prev = dip->next = AUDIO_MIXER_LAST;
908 1.24.20.1 ad dip->un.v.num_channels = 1;
909 1.24.20.1 ad strcpy(dip->un.v.units.name, AudioNtreble);
910 1.24.20.1 ad return 0;
911 1.24.20.1 ad #endif
912 1.24.20.1 ad
913 1.4 wiz case AWACS_INPUT_SELECT:
914 1.8 tsubai dip->mixer_class = AWACS_RECORD_CLASS;
915 1.8 tsubai strcpy(dip->label.name, AudioNsource);
916 1.4 wiz dip->type = AUDIO_MIXER_SET;
917 1.4 wiz dip->prev = dip->next = AUDIO_MIXER_LAST;
918 1.4 wiz dip->un.s.num_mem = 3;
919 1.4 wiz strcpy(dip->un.s.member[0].label.name, AudioNcd);
920 1.4 wiz dip->un.s.member[0].mask = 1 << 0;
921 1.4 wiz strcpy(dip->un.s.member[1].label.name, AudioNmicrophone);
922 1.4 wiz dip->un.s.member[1].mask = 1 << 1;
923 1.4 wiz strcpy(dip->un.s.member[2].label.name, AudioNline);
924 1.4 wiz dip->un.s.member[2].mask = 1 << 2;
925 1.4 wiz return 0;
926 1.4 wiz
927 1.4 wiz case AWACS_VOL_INPUT:
928 1.8 tsubai dip->mixer_class = AWACS_RECORD_CLASS;
929 1.8 tsubai strcpy(dip->label.name, AudioNrecord);
930 1.4 wiz dip->type = AUDIO_MIXER_VALUE;
931 1.4 wiz dip->prev = dip->next = AUDIO_MIXER_LAST;
932 1.4 wiz dip->un.v.num_channels = 2;
933 1.4 wiz strcpy(dip->un.v.units.name, AudioNvolume);
934 1.4 wiz return 0;
935 1.4 wiz
936 1.1 tsubai case AWACS_MONITOR_CLASS:
937 1.1 tsubai dip->mixer_class = AWACS_MONITOR_CLASS;
938 1.1 tsubai strcpy(dip->label.name, AudioCmonitor);
939 1.1 tsubai dip->type = AUDIO_MIXER_CLASS;
940 1.1 tsubai dip->next = dip->prev = AUDIO_MIXER_LAST;
941 1.1 tsubai return 0;
942 1.1 tsubai
943 1.1 tsubai case AWACS_OUTPUT_CLASS:
944 1.1 tsubai dip->mixer_class = AWACS_OUTPUT_CLASS;
945 1.1 tsubai strcpy(dip->label.name, AudioCoutputs);
946 1.4 wiz dip->type = AUDIO_MIXER_CLASS;
947 1.4 wiz dip->next = dip->prev = AUDIO_MIXER_LAST;
948 1.4 wiz return 0;
949 1.4 wiz
950 1.4 wiz case AWACS_RECORD_CLASS:
951 1.8 tsubai dip->mixer_class = AWACS_RECORD_CLASS;
952 1.4 wiz strcpy(dip->label.name, AudioCrecord);
953 1.1 tsubai dip->type = AUDIO_MIXER_CLASS;
954 1.1 tsubai dip->next = dip->prev = AUDIO_MIXER_LAST;
955 1.1 tsubai return 0;
956 1.1 tsubai }
957 1.1 tsubai
958 1.1 tsubai return ENXIO;
959 1.1 tsubai }
960 1.1 tsubai
961 1.1 tsubai size_t
962 1.23 kent awacs_round_buffersize(void *h, int dir, size_t size)
963 1.1 tsubai {
964 1.23 kent
965 1.1 tsubai if (size > 65536)
966 1.1 tsubai size = 65536;
967 1.1 tsubai return size;
968 1.1 tsubai }
969 1.1 tsubai
970 1.1 tsubai paddr_t
971 1.23 kent awacs_mappage(void *h, void *mem, off_t off, int prot)
972 1.1 tsubai {
973 1.23 kent
974 1.1 tsubai if (off < 0)
975 1.1 tsubai return -1;
976 1.1 tsubai return -1; /* XXX */
977 1.1 tsubai }
978 1.1 tsubai
979 1.1 tsubai int
980 1.23 kent awacs_get_props(void *h)
981 1.1 tsubai {
982 1.1 tsubai return AUDIO_PROP_FULLDUPLEX /* | AUDIO_PROP_MMAP */;
983 1.1 tsubai }
984 1.1 tsubai
985 1.1 tsubai int
986 1.23 kent awacs_trigger_output(void *h, void *start, void *end, int bsize,
987 1.23 kent void (*intr)(void *), void *arg,
988 1.23 kent const audio_params_t *param)
989 1.1 tsubai {
990 1.23 kent struct awacs_softc *sc;
991 1.23 kent struct dbdma_command *cmd;
992 1.1 tsubai vaddr_t va;
993 1.1 tsubai int i, len, intmode;
994 1.1 tsubai
995 1.1 tsubai DPRINTF("trigger_output %p %p 0x%x\n", start, end, bsize);
996 1.23 kent sc = h;
997 1.23 kent cmd = sc->sc_odmacmd;
998 1.1 tsubai sc->sc_ointr = intr;
999 1.1 tsubai sc->sc_oarg = arg;
1000 1.17 thorpej sc->sc_opages = ((char *)end - (char *)start) / PAGE_SIZE;
1001 1.1 tsubai
1002 1.1 tsubai #ifdef DIAGNOSTIC
1003 1.1 tsubai if (sc->sc_opages > 16)
1004 1.1 tsubai panic("awacs_trigger_output");
1005 1.1 tsubai #endif
1006 1.1 tsubai
1007 1.1 tsubai va = (vaddr_t)start;
1008 1.1 tsubai len = 0;
1009 1.1 tsubai for (i = sc->sc_opages; i > 0; i--) {
1010 1.17 thorpej len += PAGE_SIZE;
1011 1.1 tsubai if (len < bsize)
1012 1.1 tsubai intmode = DBDMA_INT_NEVER;
1013 1.1 tsubai else {
1014 1.1 tsubai len = 0;
1015 1.1 tsubai intmode = DBDMA_INT_ALWAYS;
1016 1.1 tsubai }
1017 1.1 tsubai
1018 1.17 thorpej DBDMA_BUILD(cmd, DBDMA_CMD_OUT_MORE, 0, PAGE_SIZE, vtophys(va),
1019 1.1 tsubai intmode, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
1020 1.17 thorpej va += PAGE_SIZE;
1021 1.1 tsubai cmd++;
1022 1.1 tsubai }
1023 1.1 tsubai
1024 1.1 tsubai DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0, 0,
1025 1.1 tsubai DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_ALWAYS);
1026 1.1 tsubai dbdma_st32(&cmd->d_cmddep, vtophys((vaddr_t)sc->sc_odmacmd));
1027 1.1 tsubai
1028 1.1 tsubai dbdma_start(sc->sc_odma, sc->sc_odmacmd);
1029 1.1 tsubai
1030 1.1 tsubai return 0;
1031 1.1 tsubai }
1032 1.1 tsubai
1033 1.1 tsubai int
1034 1.23 kent awacs_trigger_input(void *h, void *start, void *end, int bsize,
1035 1.23 kent void (*intr)(void *), void *arg,
1036 1.23 kent const audio_params_t *param)
1037 1.1 tsubai {
1038 1.23 kent
1039 1.1 tsubai printf("awacs_trigger_input called\n");
1040 1.1 tsubai return 1;
1041 1.1 tsubai }
1042 1.1 tsubai
1043 1.1 tsubai void
1044 1.24.20.1 ad awacs_select_output(struct awacs_softc *sc, int mask)
1045 1.1 tsubai {
1046 1.1 tsubai
1047 1.24.20.1 ad #if NSGSMIX > 0
1048 1.24.20.1 ad if (sc->sc_sgsmix) {
1049 1.24.20.1 ad if (mask & OUTPUT_HEADPHONES) {
1050 1.24.20.1 ad /* mute speakers */
1051 1.24.20.1 ad sgsmix_set_speaker_vol(sc->sc_sgsmix, 0, 0);
1052 1.24.20.1 ad sgsmix_set_headphone_vol(sc->sc_sgsmix,
1053 1.24.20.1 ad sc->hph_l, sc->hph_r);
1054 1.24.20.1 ad }
1055 1.24.20.1 ad if (mask & OUTPUT_SPEAKER) {
1056 1.24.20.1 ad /* mute headphones */
1057 1.24.20.1 ad sgsmix_set_speaker_vol(sc->sc_sgsmix,
1058 1.24.20.1 ad sc->hph_l, sc->hph_r);
1059 1.24.20.1 ad sgsmix_set_headphone_vol(sc->sc_sgsmix, 0, 0);
1060 1.24.20.1 ad }
1061 1.24.20.1 ad } else {
1062 1.24.20.1 ad #endif
1063 1.24.20.1 ad sc->sc_codecctl1 |= AWACS_MUTE_SPEAKER | AWACS_MUTE_HEADPHONE;
1064 1.24.20.1 ad if (mask & 1 << 0)
1065 1.24.20.1 ad sc->sc_codecctl1 &= ~AWACS_MUTE_SPEAKER;
1066 1.24.20.1 ad if (mask & 1 << 1)
1067 1.24.20.1 ad sc->sc_codecctl1 &= ~AWACS_MUTE_HEADPHONE;
1068 1.24.20.1 ad
1069 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl1);
1070 1.24.20.1 ad #if NSGSMIX > 0
1071 1.24.20.1 ad }
1072 1.24.20.1 ad #endif
1073 1.24.20.1 ad sc->sc_output_mask = mask;
1074 1.24.20.1 ad }
1075 1.24.20.1 ad
1076 1.24.20.1 ad void
1077 1.24.20.1 ad awacs_set_speaker_volume(struct awacs_softc *sc, int left, int right)
1078 1.24.20.1 ad {
1079 1.1 tsubai
1080 1.24.20.1 ad #if NSGSMIX > 0
1081 1.24.20.1 ad if (sc->sc_sgsmix) {
1082 1.24.20.1 ad if (sc->sc_output_mask & OUTPUT_SPEAKER)
1083 1.24.20.1 ad sgsmix_set_speaker_vol(sc->sc_sgsmix, left, right);
1084 1.24.20.1 ad } else
1085 1.24.20.1 ad #endif
1086 1.24.20.1 ad {
1087 1.24.20.1 ad int lval;
1088 1.24.20.1 ad int rval;
1089 1.24.20.1 ad
1090 1.24.20.1 ad lval = 15 - (left & 0xff) / 16;
1091 1.24.20.1 ad rval = 15 - (right & 0xff) / 16;
1092 1.24.20.1 ad DPRINTF("speaker_volume %d %d\n", lval, rval);
1093 1.24.20.1 ad
1094 1.24.20.1 ad sc->sc_codecctl4 &= ~0x3cf;
1095 1.24.20.1 ad sc->sc_codecctl4 |= (lval << 6) | rval;
1096 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl4);
1097 1.24.20.1 ad }
1098 1.24.20.1 ad sc->spk_l = left;
1099 1.24.20.1 ad sc->spk_r = right;
1100 1.1 tsubai }
1101 1.1 tsubai
1102 1.1 tsubai void
1103 1.23 kent awacs_set_ext_volume(struct awacs_softc *sc, int left, int right)
1104 1.1 tsubai {
1105 1.24.20.1 ad
1106 1.24.20.1 ad #if NSGSMIX > 0
1107 1.24.20.1 ad if (sc->sc_sgsmix) {
1108 1.24.20.1 ad if (sc->sc_output_mask & OUTPUT_HEADPHONES)
1109 1.24.20.1 ad sgsmix_set_headphone_vol(sc->sc_sgsmix, left, right);
1110 1.24.20.1 ad } else
1111 1.24.20.1 ad #endif
1112 1.24.20.1 ad {
1113 1.24.20.1 ad int lval;
1114 1.24.20.1 ad int rval;
1115 1.24.20.1 ad
1116 1.24.20.1 ad lval = 15 - (left & 0xff) / 16;
1117 1.24.20.1 ad rval = 15 - (right & 0xff) / 16;
1118 1.24.20.1 ad DPRINTF("ext_volume %d %d\n", lval, rval);
1119 1.24.20.1 ad
1120 1.24.20.1 ad sc->sc_codecctl2 &= ~0x3cf;
1121 1.24.20.1 ad sc->sc_codecctl2 |= (lval << 6) | rval;
1122 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl2);
1123 1.24.20.1 ad }
1124 1.24.20.1 ad sc->hph_l = left;
1125 1.24.20.1 ad sc->hph_r = right;
1126 1.24.20.1 ad }
1127 1.24.20.1 ad
1128 1.24.20.1 ad #if NSGSMIX > 0
1129 1.24.20.1 ad static void
1130 1.24.20.1 ad awacs_set_bass(struct awacs_softc *sc, int bass)
1131 1.24.20.1 ad {
1132 1.24.20.1 ad
1133 1.24.20.1 ad if (sc->sc_bass == bass)
1134 1.24.20.1 ad return;
1135 1.24.20.1 ad
1136 1.24.20.1 ad sc->sc_bass = bass;
1137 1.24.20.1 ad if (sc->sc_sgsmix)
1138 1.24.20.1 ad sgsmix_set_bass_treble(sc->sc_sgsmix, sc->sc_bass, sc->sc_treble);
1139 1.24.20.1 ad }
1140 1.24.20.1 ad
1141 1.24.20.1 ad static void
1142 1.24.20.1 ad awacs_set_treble(struct awacs_softc *sc, int treble)
1143 1.24.20.1 ad {
1144 1.24.20.1 ad
1145 1.24.20.1 ad if (sc->sc_treble == treble)
1146 1.24.20.1 ad return;
1147 1.24.20.1 ad
1148 1.24.20.1 ad sc->sc_treble = treble;
1149 1.24.20.1 ad if (sc->sc_sgsmix)
1150 1.24.20.1 ad sgsmix_set_bass_treble(sc->sc_sgsmix, sc->sc_bass, sc->sc_treble);
1151 1.24.20.1 ad }
1152 1.24.20.1 ad #endif
1153 1.24.20.1 ad
1154 1.24.20.1 ad void
1155 1.24.20.1 ad awacs_set_loopthrough_volume(struct awacs_softc *sc, int left, int right)
1156 1.24.20.1 ad {
1157 1.23 kent int lval;
1158 1.23 kent int rval;
1159 1.1 tsubai
1160 1.23 kent lval = 15 - (left & 0xff) / 16;
1161 1.23 kent rval = 15 - (right & 0xff) / 16;
1162 1.24.20.1 ad DPRINTF("loopthrough_volume %d %d\n", lval, rval);
1163 1.1 tsubai
1164 1.24.20.1 ad sc->sc_codecctl5 &= ~0x3cf;
1165 1.24.20.1 ad sc->sc_codecctl5 |= (lval << 6) | rval;
1166 1.24.20.1 ad awacs_write_codec(sc, sc->sc_codecctl5);
1167 1.1 tsubai }
1168 1.1 tsubai
1169 1.1 tsubai int
1170 1.23 kent awacs_set_rate(struct awacs_softc *sc, const audio_params_t *p)
1171 1.1 tsubai {
1172 1.1 tsubai int c;
1173 1.1 tsubai
1174 1.15 wiz switch (p->sample_rate) {
1175 1.1 tsubai case 44100:
1176 1.1 tsubai c = AWACS_RATE_44100;
1177 1.1 tsubai break;
1178 1.1 tsubai case 29400:
1179 1.1 tsubai c = AWACS_RATE_29400;
1180 1.1 tsubai break;
1181 1.1 tsubai case 22050:
1182 1.1 tsubai c = AWACS_RATE_22050;
1183 1.1 tsubai break;
1184 1.1 tsubai case 17640:
1185 1.1 tsubai c = AWACS_RATE_17640;
1186 1.1 tsubai break;
1187 1.1 tsubai case 14700:
1188 1.1 tsubai c = AWACS_RATE_14700;
1189 1.1 tsubai break;
1190 1.1 tsubai case 11025:
1191 1.1 tsubai c = AWACS_RATE_11025;
1192 1.1 tsubai break;
1193 1.1 tsubai case 8820:
1194 1.1 tsubai c = AWACS_RATE_8820;
1195 1.1 tsubai break;
1196 1.1 tsubai case 7350:
1197 1.1 tsubai c = AWACS_RATE_7350;
1198 1.1 tsubai break;
1199 1.1 tsubai default:
1200 1.1 tsubai return -1;
1201 1.1 tsubai }
1202 1.1 tsubai
1203 1.1 tsubai sc->sc_soundctl &= ~AWACS_RATE_MASK;
1204 1.1 tsubai sc->sc_soundctl |= c;
1205 1.1 tsubai awacs_write_reg(sc, AWACS_SOUND_CTRL, sc->sc_soundctl);
1206 1.1 tsubai
1207 1.1 tsubai return 0;
1208 1.1 tsubai }
1209