gus.c revision 1.115 1 1.115 isaki /* $NetBSD: gus.c,v 1.115 2019/03/16 12:09:58 isaki Exp $ */
2 1.2 cgd
3 1.5 jtc /*-
4 1.107 jmcneill * Copyright (c) 1996, 1999, 2008 The NetBSD Foundation, Inc.
5 1.5 jtc * All rights reserved.
6 1.5 jtc *
7 1.5 jtc * This code is derived from software contributed to The NetBSD Foundation
8 1.5 jtc * by Ken Hornstein and John Kohl.
9 1.1 brezak *
10 1.1 brezak * Redistribution and use in source and binary forms, with or without
11 1.1 brezak * modification, are permitted provided that the following conditions
12 1.1 brezak * are met:
13 1.1 brezak * 1. Redistributions of source code must retain the above copyright
14 1.1 brezak * notice, this list of conditions and the following disclaimer.
15 1.1 brezak * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 brezak * notice, this list of conditions and the following disclaimer in the
17 1.1 brezak * documentation and/or other materials provided with the distribution.
18 1.1 brezak *
19 1.6 jtc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.6 jtc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.6 jtc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.45 jtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.45 jtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.6 jtc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.6 jtc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.6 jtc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.6 jtc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.6 jtc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.6 jtc * POSSIBILITY OF SUCH DAMAGE.
30 1.1 brezak */
31 1.2 cgd
32 1.1 brezak /*
33 1.2 cgd *
34 1.1 brezak * TODO:
35 1.1 brezak * . figure out why mixer activity while sound is playing causes problems
36 1.1 brezak * (phantom interrupts?)
37 1.87 kent * . figure out a better deinterleave strategy that avoids sucking up
38 1.1 brezak * CPU, memory and cache bandwidth. (Maybe a special encoding?
39 1.1 brezak * Maybe use the double-speed sampling/hardware deinterleave trick
40 1.1 brezak * from the GUS SDK?) A 486/33 isn't quite fast enough to keep
41 1.1 brezak * up with 44.1kHz 16-bit stereo output without some drop-outs.
42 1.79 wiz * . use CS4231 for 16-bit sampling, for A-law and mu-law playback.
43 1.1 brezak * . actually test full-duplex sampling(recording) and playback.
44 1.1 brezak */
45 1.2 cgd
46 1.1 brezak /*
47 1.1 brezak * Gravis UltraSound driver
48 1.1 brezak *
49 1.1 brezak * For more detailed information, see the GUS developers' kit
50 1.1 brezak * available on the net at:
51 1.1 brezak *
52 1.53 augustss * http://www.gravis.com/Public/sdk/GUSDK222.ZIP
53 1.53 augustss *
54 1.1 brezak * See ultrawrd.doc inside--it's MS Word (ick), but it's the bible
55 1.1 brezak *
56 1.1 brezak */
57 1.2 cgd
58 1.1 brezak /*
59 1.1 brezak * The GUS Max has a slightly strange set of connections between the CS4231
60 1.1 brezak * and the GF1 and the DMA interconnects. It's set up so that the CS4231 can
61 1.1 brezak * be playing while the GF1 is loading patches from the system.
62 1.1 brezak *
63 1.1 brezak * Here's a recreation of the DMA interconnect diagram:
64 1.1 brezak *
65 1.1 brezak * GF1
66 1.1 brezak * +---------+ digital
67 1.1 brezak * | | record ASIC
68 1.1 brezak * | |--------------+
69 1.1 brezak * | | | +--------+
70 1.1 brezak * | | play (dram) | +----+ | |
71 1.1 brezak * | |--------------(------|-\ | | +-+ |
72 1.80 wiz * +---------+ | | >-|----|---|C|--|------ DMA chan 1
73 1.87 kent * | +---|-/ | | +-+ |
74 1.1 brezak * | | +----+ | | |
75 1.1 brezak * | | +----+ | | |
76 1.1 brezak * +---------+ +-+ +--(---|-\ | | | |
77 1.80 wiz * | | play |8| | | >-|----|----+---|------ DMA chan 2
78 1.1 brezak * | ---C----|--------|/|------(---|-/ | | |
79 1.1 brezak * | ^ |record |1| | +----+ | |
80 1.87 kent * | | | /----|6|------+ +--------+
81 1.1 brezak * | ---+----|--/ +-+
82 1.1 brezak * +---------+
83 1.87 kent * CS4231 8-to-16 bit bus conversion, if needed
84 1.1 brezak *
85 1.1 brezak *
86 1.1 brezak * "C" is an optional combiner.
87 1.1 brezak *
88 1.1 brezak */
89 1.73 lukem
90 1.73 lukem #include <sys/cdefs.h>
91 1.115 isaki __KERNEL_RCSID(0, "$NetBSD: gus.c,v 1.115 2019/03/16 12:09:58 isaki Exp $");
92 1.1 brezak
93 1.1 brezak #include <sys/param.h>
94 1.1 brezak #include <sys/systm.h>
95 1.69 thorpej #include <sys/callout.h>
96 1.1 brezak #include <sys/errno.h>
97 1.1 brezak #include <sys/ioctl.h>
98 1.1 brezak #include <sys/syslog.h>
99 1.1 brezak #include <sys/device.h>
100 1.1 brezak #include <sys/proc.h>
101 1.1 brezak #include <sys/buf.h>
102 1.1 brezak #include <sys/fcntl.h>
103 1.107 jmcneill #include <sys/kmem.h>
104 1.1 brezak #include <sys/kernel.h>
105 1.100 ad #include <sys/cpu.h>
106 1.100 ad #include <sys/intr.h>
107 1.100 ad #include <sys/bus.h>
108 1.107 jmcneill #include <sys/audioio.h>
109 1.99 ad
110 1.1 brezak #include <dev/audio_if.h>
111 1.1 brezak #include <dev/mulaw.h>
112 1.36 augustss #include <dev/auconv.h>
113 1.1 brezak
114 1.1 brezak #include <dev/ic/ics2101reg.h>
115 1.1 brezak #include <dev/ic/cs4231reg.h>
116 1.1 brezak #include <dev/ic/ad1848reg.h>
117 1.107 jmcneill
118 1.107 jmcneill #include <dev/isa/isavar.h>
119 1.107 jmcneill #include <dev/isa/isadmavar.h>
120 1.1 brezak #include <dev/isa/ics2101var.h>
121 1.1 brezak #include <dev/isa/ad1848var.h>
122 1.12 jtk #include <dev/isa/cs4231var.h>
123 1.107 jmcneill #include <dev/isa/gusreg.h>
124 1.1 brezak
125 1.8 jtk #ifdef AUDIO_DEBUG
126 1.8 jtk #define STATIC /* empty; for debugging symbols */
127 1.8 jtk #else
128 1.8 jtk #define STATIC static
129 1.8 jtk #endif
130 1.8 jtk
131 1.107 jmcneill #define GUS_MAX_BLOCKSIZE 65536
132 1.107 jmcneill
133 1.1 brezak /*
134 1.1 brezak * Software state of a single "voice" on the GUS
135 1.1 brezak */
136 1.1 brezak
137 1.1 brezak struct gus_voice {
138 1.1 brezak
139 1.1 brezak /*
140 1.1 brezak * Various control bits
141 1.1 brezak */
142 1.1 brezak
143 1.1 brezak unsigned char voccntl; /* State of voice control register */
144 1.1 brezak unsigned char volcntl; /* State of volume control register */
145 1.1 brezak unsigned char pan_pos; /* Position of volume panning (4 bits) */
146 1.1 brezak int rate; /* Sample rate of voice being played back */
147 1.1 brezak
148 1.1 brezak /*
149 1.1 brezak * Address of the voice data into the GUS's DRAM. 20 bits each
150 1.1 brezak */
151 1.1 brezak
152 1.1 brezak u_long start_addr; /* Starting address of voice data loop area */
153 1.1 brezak u_long end_addr; /* Ending address of voice data loop */
154 1.1 brezak u_long current_addr; /* Beginning address of voice data
155 1.1 brezak (start playing here) */
156 1.1 brezak
157 1.1 brezak /*
158 1.1 brezak * linear volume values for the GUS's volume ramp. 0-511 (9 bits).
159 1.1 brezak * These values must be translated into the logarithmic values using
160 1.1 brezak * gus_log_volumes[]
161 1.1 brezak */
162 1.1 brezak
163 1.1 brezak int start_volume; /* Starting position of volume ramp */
164 1.1 brezak int current_volume; /* Current position of volume on volume ramp */
165 1.1 brezak int end_volume; /* Ending position of volume on volume ramp */
166 1.1 brezak };
167 1.1 brezak
168 1.1 brezak /*
169 1.1 brezak * Software state of GUS
170 1.1 brezak */
171 1.1 brezak
172 1.1 brezak struct gus_softc {
173 1.109 chs device_t sc_dev; /* base device */
174 1.107 jmcneill kmutex_t sc_lock;
175 1.107 jmcneill kmutex_t sc_intr_lock;
176 1.1 brezak void *sc_ih; /* interrupt vector */
177 1.22 augustss bus_space_tag_t sc_iot; /* tag */
178 1.43 augustss bus_space_handle_t sc_ioh1; /* handle */
179 1.43 augustss bus_space_handle_t sc_ioh2; /* handle */
180 1.43 augustss bus_space_handle_t sc_ioh3; /* ICS2101 handle */
181 1.43 augustss bus_space_handle_t sc_ioh4; /* MIDI handle */
182 1.112 nat char padding[20];
183 1.1 brezak
184 1.98 ad callout_t sc_dmaout_ch;
185 1.69 thorpej
186 1.112 nat isa_chipset_tag_t sc_ic; /* ISA chipset info */
187 1.112 nat char padding1[4];
188 1.3 mycroft int sc_irq; /* IRQ used */
189 1.66 mycroft int sc_playdrq; /* DMA channel for play */
190 1.68 thorpej bus_size_t sc_play_maxsize; /* DMA size for play */
191 1.3 mycroft int sc_recdrq; /* DMA channel for recording */
192 1.68 thorpej bus_size_t sc_req_maxsize; /* DMA size for recording */
193 1.1 brezak
194 1.1 brezak int sc_flags; /* Various flags about the GUS */
195 1.1 brezak #define GUS_MIXER_INSTALLED 0x01 /* An ICS mixer is installed */
196 1.1 brezak #define GUS_LOCKED 0x02 /* GUS is busy doing multi-phase DMA */
197 1.1 brezak #define GUS_CODEC_INSTALLED 0x04 /* CS4231 installed/MAX */
198 1.1 brezak #define GUS_PLAYING 0x08 /* GUS is playing a voice */
199 1.1 brezak #define GUS_DMAOUT_ACTIVE 0x10 /* GUS is busy doing audio DMA */
200 1.1 brezak #define GUS_DMAIN_ACTIVE 0x20 /* GUS is busy sampling */
201 1.1 brezak #define GUS_OPEN 0x100 /* GUS is open */
202 1.1 brezak int sc_dsize; /* Size of GUS DRAM */
203 1.1 brezak int sc_voices; /* Number of active voices */
204 1.1 brezak u_char sc_revision; /* Board revision of GUS */
205 1.1 brezak u_char sc_mixcontrol; /* Value of GUS_MIX_CONTROL register */
206 1.1 brezak
207 1.1 brezak u_long sc_orate; /* Output sampling rate */
208 1.1 brezak u_long sc_irate; /* Input sampling rate */
209 1.1 brezak
210 1.1 brezak int sc_encoding; /* Current data encoding type */
211 1.1 brezak int sc_precision; /* # of bits of precision */
212 1.1 brezak int sc_channels; /* Number of active channels */
213 1.1 brezak int sc_blocksize; /* Current blocksize */
214 1.1 brezak int sc_chanblocksize; /* Current blocksize for each in-use
215 1.1 brezak channel */
216 1.1 brezak short sc_nbufs; /* how many on-GUS bufs per-channel */
217 1.1 brezak short sc_bufcnt; /* how many need to be played */
218 1.1 brezak void *sc_deintr_buf; /* deinterleave buffer for stereo */
219 1.1 brezak
220 1.1 brezak int sc_ogain; /* Output gain control */
221 1.1 brezak u_char sc_out_port; /* Current out port (generic only) */
222 1.1 brezak u_char sc_in_port; /* keep track of it when no codec */
223 1.1 brezak
224 1.87 kent void (*sc_dmaoutintr)(void*); /* DMA completion intr handler */
225 1.1 brezak void *sc_outarg; /* argument for sc_dmaoutintr() */
226 1.1 brezak u_char *sc_dmaoutaddr; /* for isa_dmadone */
227 1.1 brezak u_long sc_gusaddr; /* where did we just put it? */
228 1.1 brezak int sc_dmaoutcnt; /* for isa_dmadone */
229 1.1 brezak
230 1.87 kent void (*sc_dmainintr)(void*); /* DMA completion intr handler */
231 1.1 brezak void *sc_inarg; /* argument for sc_dmaoutintr() */
232 1.1 brezak u_char *sc_dmainaddr; /* for isa_dmadone */
233 1.1 brezak int sc_dmaincnt; /* for isa_dmadone */
234 1.1 brezak
235 1.1 brezak struct stereo_dma_intr {
236 1.87 kent void (*intr)(void *);
237 1.1 brezak void *arg;
238 1.1 brezak u_char *buffer;
239 1.1 brezak u_long dmabuf;
240 1.1 brezak int size;
241 1.1 brezak int flags;
242 1.1 brezak } sc_stereo;
243 1.1 brezak
244 1.1 brezak /*
245 1.1 brezak * State information for linear audio layer
246 1.1 brezak */
247 1.1 brezak
248 1.1 brezak int sc_dmabuf; /* Which ring buffer we're DMA'ing to */
249 1.1 brezak int sc_playbuf; /* Which ring buffer we're playing */
250 1.1 brezak
251 1.1 brezak /*
252 1.1 brezak * Voice information array. All voice-specific information is stored
253 1.1 brezak * here
254 1.1 brezak */
255 1.1 brezak
256 1.1 brezak struct gus_voice sc_voc[32]; /* Voice data for each voice */
257 1.1 brezak union {
258 1.1 brezak struct ics2101_softc sc_mixer_u;
259 1.60 pk struct ad1848_isa_softc sc_codec_u;
260 1.1 brezak } u;
261 1.112 nat int sc_iobase; /* I/O base address */
262 1.1 brezak #define sc_mixer u.sc_mixer_u
263 1.1 brezak #define sc_codec u.sc_codec_u
264 1.1 brezak };
265 1.1 brezak
266 1.1 brezak struct ics2101_volume {
267 1.1 brezak u_char left;
268 1.1 brezak u_char right;
269 1.1 brezak };
270 1.1 brezak
271 1.1 brezak #define HAS_CODEC(sc) ((sc)->sc_flags & GUS_CODEC_INSTALLED)
272 1.1 brezak #define HAS_MIXER(sc) ((sc)->sc_flags & GUS_MIXER_INSTALLED)
273 1.1 brezak
274 1.1 brezak /*
275 1.1 brezak * Mixer devices for ICS2101
276 1.1 brezak */
277 1.1 brezak /* MIC IN mute, line in mute, line out mute are first since they can be done
278 1.1 brezak even if no ICS mixer. */
279 1.1 brezak #define GUSICS_MIC_IN_MUTE 0
280 1.1 brezak #define GUSICS_LINE_IN_MUTE 1
281 1.1 brezak #define GUSICS_MASTER_MUTE 2
282 1.1 brezak #define GUSICS_CD_MUTE 3
283 1.1 brezak #define GUSICS_DAC_MUTE 4
284 1.1 brezak #define GUSICS_MIC_IN_LVL 5
285 1.1 brezak #define GUSICS_LINE_IN_LVL 6
286 1.1 brezak #define GUSICS_CD_LVL 7
287 1.1 brezak #define GUSICS_DAC_LVL 8
288 1.1 brezak #define GUSICS_MASTER_LVL 9
289 1.1 brezak
290 1.1 brezak #define GUSICS_RECORD_SOURCE 10
291 1.1 brezak
292 1.1 brezak /* Classes */
293 1.1 brezak #define GUSICS_INPUT_CLASS 11
294 1.1 brezak #define GUSICS_OUTPUT_CLASS 12
295 1.1 brezak #define GUSICS_RECORD_CLASS 13
296 1.1 brezak
297 1.1 brezak /*
298 1.1 brezak * Mixer & MUX devices for CS4231
299 1.1 brezak */
300 1.31 jtk #define GUSMAX_MONO_LVL 0 /* mic input to MUX;
301 1.1 brezak also mono mixer input */
302 1.31 jtk #define GUSMAX_DAC_LVL 1 /* input to MUX; also mixer input */
303 1.31 jtk #define GUSMAX_LINE_IN_LVL 2 /* input to MUX; also mixer input */
304 1.31 jtk #define GUSMAX_CD_LVL 3 /* mixer input only */
305 1.31 jtk #define GUSMAX_MONITOR_LVL 4 /* digital mix (?) */
306 1.31 jtk #define GUSMAX_OUT_LVL 5 /* output level. (?) */
307 1.31 jtk #define GUSMAX_SPEAKER_LVL 6 /* pseudo-device for mute */
308 1.31 jtk #define GUSMAX_LINE_IN_MUTE 7 /* pre-mixer */
309 1.31 jtk #define GUSMAX_DAC_MUTE 8 /* pre-mixer */
310 1.31 jtk #define GUSMAX_CD_MUTE 9 /* pre-mixer */
311 1.31 jtk #define GUSMAX_MONO_MUTE 10 /* pre-mixer--microphone/mono */
312 1.31 jtk #define GUSMAX_MONITOR_MUTE 11 /* post-mixer level/mute */
313 1.31 jtk #define GUSMAX_SPEAKER_MUTE 12 /* speaker mute */
314 1.1 brezak
315 1.31 jtk #define GUSMAX_REC_LVL 13 /* post-MUX gain */
316 1.1 brezak
317 1.31 jtk #define GUSMAX_RECORD_SOURCE 14
318 1.1 brezak
319 1.1 brezak /* Classes */
320 1.31 jtk #define GUSMAX_INPUT_CLASS 15
321 1.31 jtk #define GUSMAX_RECORD_CLASS 16
322 1.31 jtk #define GUSMAX_MONITOR_CLASS 17
323 1.31 jtk #define GUSMAX_OUTPUT_CLASS 18
324 1.1 brezak
325 1.1 brezak #ifdef AUDIO_DEBUG
326 1.1 brezak #define GUSPLAYDEBUG /*XXX*/
327 1.33 augustss #define DPRINTF(x) if (gusdebug) printf x
328 1.33 augustss #define DMAPRINTF(x) if (gusdmadebug) printf x
329 1.1 brezak int gusdebug = 0;
330 1.1 brezak int gusdmadebug = 0;
331 1.1 brezak #else
332 1.1 brezak #define DPRINTF(x)
333 1.1 brezak #define DMAPRINTF(x)
334 1.1 brezak #endif
335 1.1 brezak int gus_dostereo = 1;
336 1.1 brezak
337 1.1 brezak #define NDMARECS 2048
338 1.1 brezak #ifdef GUSPLAYDEBUG
339 1.1 brezak int gusstats = 0;
340 1.1 brezak struct dma_record {
341 1.87 kent struct timeval tv;
342 1.87 kent u_long gusaddr;
343 1.97 christos void *bsdaddr;
344 1.87 kent u_short count;
345 1.87 kent u_char channel;
346 1.87 kent u_char direction;
347 1.1 brezak } dmarecords[NDMARECS];
348 1.1 brezak
349 1.1 brezak int dmarecord_index = 0;
350 1.1 brezak #endif
351 1.1 brezak
352 1.1 brezak /*
353 1.1 brezak * local routines
354 1.1 brezak */
355 1.1 brezak
356 1.87 kent int gusopen(void *, int);
357 1.87 kent void gusclose(void *);
358 1.87 kent void gusmax_close(void *);
359 1.87 kent int gusintr(void *);
360 1.97 christos int gus_set_in_gain(void *, u_int, u_char);
361 1.97 christos int gus_get_in_gain(void *);
362 1.97 christos int gus_set_out_gain(void *, u_int, u_char);
363 1.97 christos int gus_get_out_gain(void *);
364 1.87 kent int gus_set_params(void *, int, int, audio_params_t *,
365 1.87 kent audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
366 1.87 kent int gusmax_set_params(void *, int, int, audio_params_t *,
367 1.87 kent audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
368 1.87 kent int gus_round_blocksize(void *, int, int, const audio_params_t *);
369 1.87 kent int gus_commit_settings(void *);
370 1.87 kent int gus_dma_output(void *, void *, int, void (*)(void *), void *);
371 1.87 kent int gus_dma_input(void *, void *, int, void (*)(void *), void *);
372 1.87 kent int gus_halt_out_dma(void *);
373 1.87 kent int gus_halt_in_dma(void *);
374 1.87 kent int gus_speaker_ctl(void *, int);
375 1.87 kent int gusmaxopen(void *, int);
376 1.87 kent int gusmax_round_blocksize(void *, int, int, const audio_params_t *);
377 1.87 kent int gusmax_commit_settings(void *);
378 1.87 kent int gusmax_dma_output(void *, void *, int, void (*)(void *), void *);
379 1.87 kent int gusmax_dma_input(void *, void *, int, void (*)(void *), void *);
380 1.87 kent int gusmax_halt_out_dma(void *);
381 1.87 kent int gusmax_halt_in_dma(void *);
382 1.87 kent int gusmax_speaker_ctl(void *, int);
383 1.87 kent int gus_getdev(void *, struct audio_device *);
384 1.87 kent
385 1.87 kent STATIC void gus_deinterleave(struct gus_softc *, void *, int);
386 1.87 kent
387 1.87 kent STATIC int gus_mic_ctl(void *, int);
388 1.87 kent STATIC int gus_linein_ctl(void *, int);
389 1.87 kent STATIC int gus_test_iobase(bus_space_tag_t, int);
390 1.87 kent STATIC void guspoke(bus_space_tag_t, bus_space_handle_t, long, u_char);
391 1.97 christos STATIC void gusdmaout(struct gus_softc *, int, u_long, void *, int);
392 1.87 kent STATIC int gus_init_cs4231(struct gus_softc *);
393 1.87 kent STATIC void gus_init_ics2101(struct gus_softc *);
394 1.87 kent
395 1.87 kent STATIC void gus_set_chan_addrs(struct gus_softc *);
396 1.87 kent STATIC void gusreset(struct gus_softc *, int);
397 1.87 kent STATIC void gus_set_voices(struct gus_softc *, int);
398 1.87 kent STATIC void gus_set_volume(struct gus_softc *, int, int);
399 1.87 kent STATIC void gus_set_samprate(struct gus_softc *, int, int);
400 1.87 kent STATIC void gus_set_recrate(struct gus_softc *, u_long);
401 1.87 kent STATIC void gus_start_voice(struct gus_softc *, int, int);
402 1.87 kent STATIC void gus_stop_voice(struct gus_softc *, int, int);
403 1.87 kent STATIC void gus_set_endaddr(struct gus_softc *, int, u_long);
404 1.15 jtk #ifdef GUSPLAYDEBUG
405 1.87 kent STATIC void gus_set_curaddr(struct gus_softc *, int, u_long);
406 1.87 kent STATIC u_long gus_get_curaddr(struct gus_softc *, int);
407 1.14 christos #endif
408 1.87 kent STATIC int gus_dmaout_intr(struct gus_softc *);
409 1.87 kent STATIC void gus_dmaout_dointr(struct gus_softc *);
410 1.87 kent STATIC void gus_dmaout_timeout(void *);
411 1.87 kent STATIC int gus_dmain_intr(struct gus_softc *);
412 1.87 kent STATIC int gus_voice_intr(struct gus_softc *);
413 1.87 kent STATIC void gus_start_playing(struct gus_softc *, int);
414 1.87 kent STATIC int gus_continue_playing(struct gus_softc *, int);
415 1.87 kent STATIC u_char guspeek(bus_space_tag_t, bus_space_handle_t, u_long);
416 1.87 kent STATIC u_long convert_to_16bit(u_long);
417 1.87 kent STATIC int gus_mixer_set_port(void *, mixer_ctrl_t *);
418 1.87 kent STATIC int gus_mixer_get_port(void *, mixer_ctrl_t *);
419 1.87 kent STATIC int gusmax_mixer_set_port(void *, mixer_ctrl_t *);
420 1.87 kent STATIC int gusmax_mixer_get_port(void *, mixer_ctrl_t *);
421 1.87 kent STATIC int gus_mixer_query_devinfo(void *, mixer_devinfo_t *);
422 1.87 kent STATIC int gusmax_mixer_query_devinfo(void *, mixer_devinfo_t *);
423 1.87 kent STATIC int gus_query_encoding(void *, struct audio_encoding *);
424 1.87 kent STATIC int gus_get_props(void *);
425 1.87 kent STATIC int gusmax_get_props(void *);
426 1.87 kent
427 1.87 kent STATIC void gusics_master_mute(struct ics2101_softc *, int);
428 1.87 kent STATIC void gusics_dac_mute(struct ics2101_softc *, int);
429 1.87 kent STATIC void gusics_mic_mute(struct ics2101_softc *, int);
430 1.87 kent STATIC void gusics_linein_mute(struct ics2101_softc *, int);
431 1.87 kent STATIC void gusics_cd_mute(struct ics2101_softc *, int);
432 1.1 brezak
433 1.87 kent void stereo_dmaintr(void *);
434 1.14 christos
435 1.1 brezak /*
436 1.1 brezak * ISA bus driver routines
437 1.1 brezak */
438 1.1 brezak
439 1.105 cegger int gusprobe(device_t, cfdata_t, void *);
440 1.105 cegger void gusattach(device_t, device_t, void *);
441 1.7 mycroft
442 1.109 chs CFATTACH_DECL_NEW(gus, sizeof(struct gus_softc),
443 1.77 thorpej gusprobe, gusattach, NULL, NULL);
444 1.1 brezak
445 1.1 brezak /*
446 1.1 brezak * A mapping from IRQ/DRQ values to the values used in the GUS's internal
447 1.1 brezak * registers. A zero means that the referenced IRQ/DRQ is invalid
448 1.1 brezak */
449 1.1 brezak
450 1.70 jdolecek static const int gus_irq_map[] = {
451 1.84 drochner -1, -1, 1, 3, -1, 2, -1, 4,
452 1.84 drochner -1, 1, -1, 5, 6, -1, -1, 7
453 1.3 mycroft };
454 1.70 jdolecek static const int gus_drq_map[] = {
455 1.84 drochner -1, 1, -1, 2, -1, 3, 4, 5
456 1.3 mycroft };
457 1.1 brezak
458 1.1 brezak /*
459 1.1 brezak * A list of valid base addresses for the GUS
460 1.1 brezak */
461 1.1 brezak
462 1.70 jdolecek static const int gus_base_addrs[] = {
463 1.3 mycroft 0x210, 0x220, 0x230, 0x240, 0x250, 0x260
464 1.3 mycroft };
465 1.70 jdolecek static const int gus_addrs = sizeof(gus_base_addrs) / sizeof(gus_base_addrs[0]);
466 1.1 brezak
467 1.1 brezak /*
468 1.1 brezak * Maximum frequency values of the GUS based on the number of currently active
469 1.1 brezak * voices. Since the GUS samples a voice every 1.6 us, the maximum frequency
470 1.1 brezak * is dependent on the number of active voices. Yes, it is pretty weird.
471 1.1 brezak */
472 1.1 brezak
473 1.70 jdolecek static const int gus_max_frequency[] = {
474 1.1 brezak 44100, /* 14 voices */
475 1.1 brezak 41160, /* 15 voices */
476 1.1 brezak 38587, /* 16 voices */
477 1.1 brezak 36317, /* 17 voices */
478 1.1 brezak 34300, /* 18 voices */
479 1.1 brezak 32494, /* 19 voices */
480 1.1 brezak 30870, /* 20 voices */
481 1.1 brezak 29400, /* 21 voices */
482 1.1 brezak 28063, /* 22 voices */
483 1.1 brezak 26843, /* 23 voices */
484 1.1 brezak 25725, /* 24 voices */
485 1.1 brezak 24696, /* 25 voices */
486 1.1 brezak 23746, /* 26 voices */
487 1.1 brezak 22866, /* 27 voices */
488 1.1 brezak 22050, /* 28 voices */
489 1.1 brezak 21289, /* 29 voices */
490 1.1 brezak 20580, /* 30 voices */
491 1.1 brezak 19916, /* 31 voices */
492 1.1 brezak 19293 /* 32 voices */
493 1.1 brezak };
494 1.1 brezak /*
495 1.1 brezak * A mapping of linear volume levels to the logarithmic volume values used
496 1.1 brezak * by the GF1 chip on the GUS. From GUS SDK vol1.c.
497 1.1 brezak */
498 1.1 brezak
499 1.70 jdolecek static const unsigned short gus_log_volumes[512] = {
500 1.1 brezak 0x0000,
501 1.1 brezak 0x0700, 0x07ff, 0x0880, 0x08ff, 0x0940, 0x0980, 0x09c0, 0x09ff, 0x0a20,
502 1.1 brezak 0x0a40, 0x0a60, 0x0a80, 0x0aa0, 0x0ac0, 0x0ae0, 0x0aff, 0x0b10, 0x0b20,
503 1.1 brezak 0x0b30, 0x0b40, 0x0b50, 0x0b60, 0x0b70, 0x0b80, 0x0b90, 0x0ba0, 0x0bb0,
504 1.1 brezak 0x0bc0, 0x0bd0, 0x0be0, 0x0bf0, 0x0bff, 0x0c08, 0x0c10, 0x0c18, 0x0c20,
505 1.1 brezak 0x0c28, 0x0c30, 0x0c38, 0x0c40, 0x0c48, 0x0c50, 0x0c58, 0x0c60, 0x0c68,
506 1.1 brezak 0x0c70, 0x0c78, 0x0c80, 0x0c88, 0x0c90, 0x0c98, 0x0ca0, 0x0ca8, 0x0cb0,
507 1.1 brezak 0x0cb8, 0x0cc0, 0x0cc8, 0x0cd0, 0x0cd8, 0x0ce0, 0x0ce8, 0x0cf0, 0x0cf8,
508 1.1 brezak 0x0cff, 0x0d04, 0x0d08, 0x0d0c, 0x0d10, 0x0d14, 0x0d18, 0x0d1c, 0x0d20,
509 1.1 brezak 0x0d24, 0x0d28, 0x0d2c, 0x0d30, 0x0d34, 0x0d38, 0x0d3c, 0x0d40, 0x0d44,
510 1.1 brezak 0x0d48, 0x0d4c, 0x0d50, 0x0d54, 0x0d58, 0x0d5c, 0x0d60, 0x0d64, 0x0d68,
511 1.1 brezak 0x0d6c, 0x0d70, 0x0d74, 0x0d78, 0x0d7c, 0x0d80, 0x0d84, 0x0d88, 0x0d8c,
512 1.1 brezak 0x0d90, 0x0d94, 0x0d98, 0x0d9c, 0x0da0, 0x0da4, 0x0da8, 0x0dac, 0x0db0,
513 1.1 brezak 0x0db4, 0x0db8, 0x0dbc, 0x0dc0, 0x0dc4, 0x0dc8, 0x0dcc, 0x0dd0, 0x0dd4,
514 1.1 brezak 0x0dd8, 0x0ddc, 0x0de0, 0x0de4, 0x0de8, 0x0dec, 0x0df0, 0x0df4, 0x0df8,
515 1.1 brezak 0x0dfc, 0x0dff, 0x0e02, 0x0e04, 0x0e06, 0x0e08, 0x0e0a, 0x0e0c, 0x0e0e,
516 1.1 brezak 0x0e10, 0x0e12, 0x0e14, 0x0e16, 0x0e18, 0x0e1a, 0x0e1c, 0x0e1e, 0x0e20,
517 1.1 brezak 0x0e22, 0x0e24, 0x0e26, 0x0e28, 0x0e2a, 0x0e2c, 0x0e2e, 0x0e30, 0x0e32,
518 1.1 brezak 0x0e34, 0x0e36, 0x0e38, 0x0e3a, 0x0e3c, 0x0e3e, 0x0e40, 0x0e42, 0x0e44,
519 1.1 brezak 0x0e46, 0x0e48, 0x0e4a, 0x0e4c, 0x0e4e, 0x0e50, 0x0e52, 0x0e54, 0x0e56,
520 1.1 brezak 0x0e58, 0x0e5a, 0x0e5c, 0x0e5e, 0x0e60, 0x0e62, 0x0e64, 0x0e66, 0x0e68,
521 1.1 brezak 0x0e6a, 0x0e6c, 0x0e6e, 0x0e70, 0x0e72, 0x0e74, 0x0e76, 0x0e78, 0x0e7a,
522 1.1 brezak 0x0e7c, 0x0e7e, 0x0e80, 0x0e82, 0x0e84, 0x0e86, 0x0e88, 0x0e8a, 0x0e8c,
523 1.1 brezak 0x0e8e, 0x0e90, 0x0e92, 0x0e94, 0x0e96, 0x0e98, 0x0e9a, 0x0e9c, 0x0e9e,
524 1.1 brezak 0x0ea0, 0x0ea2, 0x0ea4, 0x0ea6, 0x0ea8, 0x0eaa, 0x0eac, 0x0eae, 0x0eb0,
525 1.1 brezak 0x0eb2, 0x0eb4, 0x0eb6, 0x0eb8, 0x0eba, 0x0ebc, 0x0ebe, 0x0ec0, 0x0ec2,
526 1.1 brezak 0x0ec4, 0x0ec6, 0x0ec8, 0x0eca, 0x0ecc, 0x0ece, 0x0ed0, 0x0ed2, 0x0ed4,
527 1.1 brezak 0x0ed6, 0x0ed8, 0x0eda, 0x0edc, 0x0ede, 0x0ee0, 0x0ee2, 0x0ee4, 0x0ee6,
528 1.1 brezak 0x0ee8, 0x0eea, 0x0eec, 0x0eee, 0x0ef0, 0x0ef2, 0x0ef4, 0x0ef6, 0x0ef8,
529 1.1 brezak 0x0efa, 0x0efc, 0x0efe, 0x0eff, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05,
530 1.1 brezak 0x0f06, 0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
531 1.1 brezak 0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16, 0x0f17,
532 1.1 brezak 0x0f18, 0x0f19, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d, 0x0f1e, 0x0f1f, 0x0f20,
533 1.1 brezak 0x0f21, 0x0f22, 0x0f23, 0x0f24, 0x0f25, 0x0f26, 0x0f27, 0x0f28, 0x0f29,
534 1.1 brezak 0x0f2a, 0x0f2b, 0x0f2c, 0x0f2d, 0x0f2e, 0x0f2f, 0x0f30, 0x0f31, 0x0f32,
535 1.1 brezak 0x0f33, 0x0f34, 0x0f35, 0x0f36, 0x0f37, 0x0f38, 0x0f39, 0x0f3a, 0x0f3b,
536 1.1 brezak 0x0f3c, 0x0f3d, 0x0f3e, 0x0f3f, 0x0f40, 0x0f41, 0x0f42, 0x0f43, 0x0f44,
537 1.1 brezak 0x0f45, 0x0f46, 0x0f47, 0x0f48, 0x0f49, 0x0f4a, 0x0f4b, 0x0f4c, 0x0f4d,
538 1.1 brezak 0x0f4e, 0x0f4f, 0x0f50, 0x0f51, 0x0f52, 0x0f53, 0x0f54, 0x0f55, 0x0f56,
539 1.1 brezak 0x0f57, 0x0f58, 0x0f59, 0x0f5a, 0x0f5b, 0x0f5c, 0x0f5d, 0x0f5e, 0x0f5f,
540 1.1 brezak 0x0f60, 0x0f61, 0x0f62, 0x0f63, 0x0f64, 0x0f65, 0x0f66, 0x0f67, 0x0f68,
541 1.1 brezak 0x0f69, 0x0f6a, 0x0f6b, 0x0f6c, 0x0f6d, 0x0f6e, 0x0f6f, 0x0f70, 0x0f71,
542 1.1 brezak 0x0f72, 0x0f73, 0x0f74, 0x0f75, 0x0f76, 0x0f77, 0x0f78, 0x0f79, 0x0f7a,
543 1.1 brezak 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f, 0x0f80, 0x0f81, 0x0f82, 0x0f83,
544 1.1 brezak 0x0f84, 0x0f85, 0x0f86, 0x0f87, 0x0f88, 0x0f89, 0x0f8a, 0x0f8b, 0x0f8c,
545 1.1 brezak 0x0f8d, 0x0f8e, 0x0f8f, 0x0f90, 0x0f91, 0x0f92, 0x0f93, 0x0f94, 0x0f95,
546 1.1 brezak 0x0f96, 0x0f97, 0x0f98, 0x0f99, 0x0f9a, 0x0f9b, 0x0f9c, 0x0f9d, 0x0f9e,
547 1.1 brezak 0x0f9f, 0x0fa0, 0x0fa1, 0x0fa2, 0x0fa3, 0x0fa4, 0x0fa5, 0x0fa6, 0x0fa7,
548 1.1 brezak 0x0fa8, 0x0fa9, 0x0faa, 0x0fab, 0x0fac, 0x0fad, 0x0fae, 0x0faf, 0x0fb0,
549 1.1 brezak 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7, 0x0fb8, 0x0fb9,
550 1.1 brezak 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf, 0x0fc0, 0x0fc1, 0x0fc2,
551 1.1 brezak 0x0fc3, 0x0fc4, 0x0fc5, 0x0fc6, 0x0fc7, 0x0fc8, 0x0fc9, 0x0fca, 0x0fcb,
552 1.1 brezak 0x0fcc, 0x0fcd, 0x0fce, 0x0fcf, 0x0fd0, 0x0fd1, 0x0fd2, 0x0fd3, 0x0fd4,
553 1.1 brezak 0x0fd5, 0x0fd6, 0x0fd7, 0x0fd8, 0x0fd9, 0x0fda, 0x0fdb, 0x0fdc, 0x0fdd,
554 1.1 brezak 0x0fde, 0x0fdf, 0x0fe0, 0x0fe1, 0x0fe2, 0x0fe3, 0x0fe4, 0x0fe5, 0x0fe6,
555 1.1 brezak 0x0fe7, 0x0fe8, 0x0fe9, 0x0fea, 0x0feb, 0x0fec, 0x0fed, 0x0fee, 0x0fef,
556 1.1 brezak 0x0ff0, 0x0ff1, 0x0ff2, 0x0ff3, 0x0ff4, 0x0ff5, 0x0ff6, 0x0ff7, 0x0ff8,
557 1.1 brezak 0x0ff9, 0x0ffa, 0x0ffb, 0x0ffc, 0x0ffd, 0x0ffe, 0x0fff};
558 1.1 brezak
559 1.43 augustss #define SELECT_GUS_REG(iot,ioh1,x) bus_space_write_1(iot,ioh1,GUS_REG_SELECT,x)
560 1.1 brezak #define ADDR_HIGH(x) (unsigned int) ((x >> 7L) & 0x1fffL)
561 1.1 brezak #define ADDR_LOW(x) (unsigned int) ((x & 0x7fL) << 9L)
562 1.1 brezak
563 1.1 brezak #define GUS_MIN_VOICES 14 /* Minimum possible number of voices */
564 1.1 brezak #define GUS_MAX_VOICES 32 /* Maximum possible number of voices */
565 1.1 brezak #define GUS_VOICE_LEFT 0 /* Voice used for left (and mono) playback */
566 1.1 brezak #define GUS_VOICE_RIGHT 1 /* Voice used for right playback */
567 1.1 brezak #define GUS_MEM_OFFSET 32 /* Offset into GUS memory to begin of buffer */
568 1.1 brezak #define GUS_BUFFER_MULTIPLE 1024 /* Audio buffers are multiples of this */
569 1.1 brezak #define GUS_MEM_FOR_BUFFERS 131072 /* use this many bytes on-GUS */
570 1.1 brezak #define GUS_LEFT_RIGHT_OFFSET (sc->sc_nbufs * sc->sc_chanblocksize + GUS_MEM_OFFSET)
571 1.1 brezak
572 1.1 brezak #define GUS_PREC_BYTES (sc->sc_precision >> 3) /* precision to bytes */
573 1.1 brezak
574 1.1 brezak /*
575 1.1 brezak * Interface to higher level audio driver
576 1.1 brezak */
577 1.1 brezak
578 1.85 yamt const struct audio_hw_if gus_hw_if = {
579 1.115 isaki .open = gusopen,
580 1.115 isaki .close = gusclose,
581 1.115 isaki .query_encoding = gus_query_encoding,
582 1.115 isaki .set_params = gus_set_params,
583 1.115 isaki .round_blocksize = gus_round_blocksize,
584 1.115 isaki .commit_settings = gus_commit_settings,
585 1.115 isaki .start_output = gus_dma_output,
586 1.115 isaki .start_input = gus_dma_input,
587 1.115 isaki .halt_output = gus_halt_out_dma,
588 1.115 isaki .halt_input = gus_halt_in_dma,
589 1.115 isaki .speaker_ctl = gus_speaker_ctl,
590 1.115 isaki .getdev = gus_getdev,
591 1.115 isaki .set_port = gus_mixer_set_port,
592 1.115 isaki .get_port = gus_mixer_get_port,
593 1.115 isaki .query_devinfo = gus_mixer_query_devinfo,
594 1.115 isaki .allocm = ad1848_isa_malloc,
595 1.115 isaki .freem = ad1848_isa_free,
596 1.115 isaki .round_buffersize = ad1848_isa_round_buffersize,
597 1.115 isaki .mappage = ad1848_isa_mappage,
598 1.115 isaki .get_props = gus_get_props,
599 1.115 isaki .get_locks = ad1848_get_locks,
600 1.1 brezak };
601 1.1 brezak
602 1.85 yamt static const struct audio_hw_if gusmax_hw_if = {
603 1.115 isaki .open = gusmaxopen,
604 1.115 isaki .close = gusmax_close,
605 1.115 isaki .query_encoding = gus_query_encoding,
606 1.115 isaki .set_params = gusmax_set_params,
607 1.115 isaki .round_blocksize = gusmax_round_blocksize,
608 1.115 isaki .commit_settings = gusmax_commit_settings,
609 1.115 isaki .start_output = gusmax_dma_output,
610 1.115 isaki .start_input = gusmax_dma_input,
611 1.115 isaki .halt_output = gusmax_halt_out_dma,
612 1.115 isaki .halt_input = gusmax_halt_in_dma,
613 1.115 isaki .speaker_ctl = gusmax_speaker_ctl,
614 1.115 isaki .getdev = gus_getdev,
615 1.115 isaki .set_port = gusmax_mixer_set_port,
616 1.115 isaki .get_port = gusmax_mixer_get_port,
617 1.115 isaki .query_devinfo = gusmax_mixer_query_devinfo,
618 1.115 isaki .allocm = ad1848_isa_malloc,
619 1.115 isaki .freem = ad1848_isa_free,
620 1.115 isaki .round_buffersize = ad1848_isa_round_buffersize,
621 1.115 isaki .mappage = ad1848_isa_mappage,
622 1.115 isaki .get_props = gusmax_get_props,
623 1.115 isaki .get_locks = ad1848_get_locks,
624 1.43 augustss };
625 1.1 brezak
626 1.1 brezak /*
627 1.1 brezak * Some info about the current audio device
628 1.1 brezak */
629 1.1 brezak
630 1.1 brezak struct audio_device gus_device = {
631 1.1 brezak "UltraSound",
632 1.1 brezak "",
633 1.1 brezak "gus",
634 1.1 brezak };
635 1.1 brezak
636 1.1 brezak #define FLIP_REV 5 /* This rev has flipped mixer chans */
637 1.1 brezak
638 1.1 brezak
639 1.1 brezak int
640 1.105 cegger gusprobe(device_t parent, cfdata_t match, void *aux)
641 1.1 brezak {
642 1.87 kent struct isa_attach_args *ia;
643 1.74 thorpej int iobase, recdrq;
644 1.74 thorpej
645 1.87 kent ia = aux;
646 1.74 thorpej if (ia->ia_nio < 1)
647 1.87 kent return 0;
648 1.74 thorpej if (ia->ia_nirq < 1)
649 1.87 kent return 0;
650 1.74 thorpej if (ia->ia_ndrq < 1)
651 1.87 kent return 0;
652 1.74 thorpej
653 1.74 thorpej if (ISA_DIRECT_CONFIG(ia))
654 1.87 kent return 0;
655 1.74 thorpej
656 1.74 thorpej iobase = ia->ia_io[0].ir_addr;
657 1.74 thorpej if (ia->ia_ndrq > 1)
658 1.74 thorpej recdrq = ia->ia_drq[1].ir_drq;
659 1.74 thorpej else
660 1.84 drochner recdrq = ISA_UNKNOWN_DRQ;
661 1.1 brezak
662 1.1 brezak /*
663 1.1 brezak * Before we do anything else, make sure requested IRQ and DRQ are
664 1.1 brezak * valid for this card.
665 1.1 brezak */
666 1.1 brezak
667 1.43 augustss /* XXX range check before indexing!! */
668 1.84 drochner if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ ||
669 1.84 drochner gus_irq_map[ia->ia_irq[0].ir_irq] == -1) {
670 1.74 thorpej printf("gus: invalid irq %d, card not probed\n",
671 1.74 thorpej ia->ia_irq[0].ir_irq);
672 1.43 augustss return 0;
673 1.1 brezak }
674 1.1 brezak
675 1.84 drochner if (ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ ||
676 1.84 drochner gus_drq_map[ia->ia_drq[0].ir_drq] == -1) {
677 1.74 thorpej printf("gus: invalid drq %d, card not probed\n",
678 1.74 thorpej ia->ia_drq[0].ir_drq);
679 1.43 augustss return 0;
680 1.1 brezak }
681 1.1 brezak
682 1.84 drochner if (recdrq != ISA_UNKNOWN_DRQ) {
683 1.84 drochner if (recdrq > 7 || gus_drq_map[recdrq] == -1) {
684 1.110 msaitoh printf("gus: invalid second DMA channel (%d), card "
685 1.110 msaitoh "not probed\n", recdrq);
686 1.87 kent return 0;
687 1.87 kent }
688 1.1 brezak } else
689 1.74 thorpej recdrq = ia->ia_drq[0].ir_drq;
690 1.1 brezak
691 1.84 drochner if (iobase == ISA_UNKNOWN_PORT) {
692 1.1 brezak int i;
693 1.87 kent for (i = 0; i < gus_addrs; i++)
694 1.50 drochner if (gus_test_iobase(ia->ia_iot, gus_base_addrs[i])) {
695 1.1 brezak iobase = gus_base_addrs[i];
696 1.1 brezak goto done;
697 1.1 brezak }
698 1.1 brezak return 0;
699 1.50 drochner } else if (!gus_test_iobase(ia->ia_iot, iobase))
700 1.1 brezak return 0;
701 1.1 brezak
702 1.1 brezak done:
703 1.74 thorpej if (!isa_drq_isfree(ia->ia_ic, ia->ia_drq[0].ir_drq) ||
704 1.74 thorpej (recdrq != ia->ia_drq[0].ir_drq &&
705 1.74 thorpej !isa_drq_isfree(ia->ia_ic, recdrq)))
706 1.44 augustss return 0;
707 1.44 augustss
708 1.74 thorpej ia->ia_nio = 1;
709 1.74 thorpej ia->ia_io[0].ir_addr = iobase;
710 1.74 thorpej ia->ia_io[0].ir_size = GUS_NPORT1;
711 1.74 thorpej
712 1.74 thorpej ia->ia_nirq = 1;
713 1.74 thorpej ia->ia_ndrq = (recdrq != ia->ia_drq[0].ir_drq) ? 2 : 1;
714 1.74 thorpej
715 1.74 thorpej ia->ia_niomem = 0;
716 1.74 thorpej
717 1.43 augustss return 1;
718 1.1 brezak }
719 1.1 brezak
720 1.1 brezak /*
721 1.1 brezak * Test to see if a particular I/O base is valid for the GUS. Return true
722 1.1 brezak * if it is.
723 1.1 brezak */
724 1.1 brezak
725 1.8 jtk STATIC int
726 1.87 kent gus_test_iobase (bus_space_tag_t iot, int iobase)
727 1.1 brezak {
728 1.43 augustss bus_space_handle_t ioh1, ioh2, ioh3, ioh4;
729 1.1 brezak u_char s1, s2;
730 1.107 jmcneill int rv;
731 1.43 augustss
732 1.87 kent rv = 0;
733 1.43 augustss /* Map i/o space */
734 1.43 augustss if (bus_space_map(iot, iobase, GUS_NPORT1, 0, &ioh1))
735 1.43 augustss return 0;
736 1.43 augustss if (bus_space_map(iot, iobase+GUS_IOH2_OFFSET, GUS_NPORT2, 0, &ioh2))
737 1.43 augustss goto bad1;
738 1.43 augustss
739 1.43 augustss /* XXX Maybe we shouldn't fail on mapping this, but just assume
740 1.43 augustss * the card is of revision 0? */
741 1.43 augustss if (bus_space_map(iot, iobase+GUS_IOH3_OFFSET, GUS_NPORT3, 0, &ioh3))
742 1.43 augustss goto bad2;
743 1.43 augustss
744 1.43 augustss if (bus_space_map(iot, iobase+GUS_IOH4_OFFSET, GUS_NPORT4, 0, &ioh4))
745 1.43 augustss goto bad3;
746 1.1 brezak
747 1.1 brezak /*
748 1.1 brezak * Reset GUS to an initial state before we do anything.
749 1.1 brezak */
750 1.1 brezak
751 1.1 brezak delay(500);
752 1.1 brezak
753 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
754 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
755 1.1 brezak
756 1.87 kent delay(500);
757 1.1 brezak
758 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
759 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, GUSMASK_MASTER_RESET);
760 1.1 brezak
761 1.87 kent delay(500);
762 1.1 brezak
763 1.1 brezak /*
764 1.1 brezak * See if we can write to the board's memory
765 1.1 brezak */
766 1.1 brezak
767 1.87 kent s1 = guspeek(iot, ioh2, 0L);
768 1.87 kent s2 = guspeek(iot, ioh2, 1L);
769 1.1 brezak
770 1.87 kent guspoke(iot, ioh2, 0L, 0xaa);
771 1.87 kent guspoke(iot, ioh2, 1L, 0x55);
772 1.1 brezak
773 1.87 kent if (guspeek(iot, ioh2, 0L) != 0xaa)
774 1.43 augustss goto bad;
775 1.1 brezak
776 1.43 augustss guspoke(iot, ioh2, 0L, s1);
777 1.43 augustss guspoke(iot, ioh2, 1L, s2);
778 1.1 brezak
779 1.50 drochner rv = 1;
780 1.43 augustss
781 1.43 augustss bad:
782 1.50 drochner bus_space_unmap(iot, ioh4, GUS_NPORT4);
783 1.43 augustss bad3:
784 1.50 drochner bus_space_unmap(iot, ioh3, GUS_NPORT3);
785 1.43 augustss bad2:
786 1.50 drochner bus_space_unmap(iot, ioh2, GUS_NPORT2);
787 1.43 augustss bad1:
788 1.50 drochner bus_space_unmap(iot, ioh1, GUS_NPORT1);
789 1.50 drochner return rv;
790 1.1 brezak }
791 1.1 brezak
792 1.1 brezak /*
793 1.1 brezak * Setup the GUS for use; called shortly after probe
794 1.1 brezak */
795 1.1 brezak
796 1.1 brezak void
797 1.105 cegger gusattach(device_t parent, device_t self, void *aux)
798 1.1 brezak {
799 1.87 kent struct gus_softc *sc;
800 1.87 kent struct isa_attach_args *ia;
801 1.50 drochner bus_space_tag_t iot;
802 1.50 drochner bus_space_handle_t ioh1, ioh2, ioh3, ioh4;
803 1.87 kent int iobase, i;
804 1.93 christos unsigned char c, m;
805 1.107 jmcneill int d = -1;
806 1.85 yamt const struct audio_hw_if *hwif;
807 1.50 drochner
808 1.109 chs sc = device_private(self);
809 1.112 nat sc->sc_dev = self;
810 1.87 kent ia = aux;
811 1.107 jmcneill callout_init(&sc->sc_dmaout_ch, CALLOUT_MPSAFE);
812 1.108 mrg ad1848_init_locks(&sc->sc_codec.sc_ad1848, IPL_AUDIO);
813 1.112 nat sc->sc_lock = sc->sc_codec.sc_ad1848.sc_lock;
814 1.112 nat sc->sc_intr_lock = sc->sc_codec.sc_ad1848.sc_intr_lock;
815 1.69 thorpej
816 1.50 drochner sc->sc_iot = iot = ia->ia_iot;
817 1.55 thorpej sc->sc_ic = ia->ia_ic;
818 1.74 thorpej iobase = ia->ia_io[0].ir_addr;
819 1.50 drochner
820 1.50 drochner /* Map i/o space */
821 1.50 drochner if (bus_space_map(iot, iobase, GUS_NPORT1, 0, &ioh1))
822 1.101 cegger panic("%s: can't map io port range 1", device_xname(self));
823 1.50 drochner sc->sc_ioh1 = ioh1;
824 1.50 drochner if (bus_space_map(iot, iobase+GUS_IOH2_OFFSET, GUS_NPORT2, 0, &ioh2))
825 1.101 cegger panic("%s: can't map io port range 2", device_xname(self));
826 1.50 drochner sc->sc_ioh2 = ioh2;
827 1.50 drochner
828 1.50 drochner /* XXX Maybe we shouldn't fail on mapping this, but just assume
829 1.50 drochner * the card is of revision 0? */
830 1.50 drochner if (bus_space_map(iot, iobase+GUS_IOH3_OFFSET, GUS_NPORT3, 0, &ioh3))
831 1.101 cegger panic("%s: can't map io port range 3", device_xname(self));
832 1.50 drochner sc->sc_ioh3 = ioh3;
833 1.50 drochner
834 1.50 drochner if (bus_space_map(iot, iobase+GUS_IOH4_OFFSET, GUS_NPORT4, 0, &ioh4))
835 1.101 cegger panic("%s: can't map io port range 4", device_xname(self));
836 1.50 drochner sc->sc_ioh4 = ioh4;
837 1.50 drochner
838 1.50 drochner sc->sc_iobase = iobase;
839 1.74 thorpej sc->sc_irq = ia->ia_irq[0].ir_irq;
840 1.74 thorpej sc->sc_playdrq = ia->ia_drq[0].ir_drq;
841 1.74 thorpej sc->sc_recdrq = (ia->ia_ndrq == 2) ?
842 1.74 thorpej ia->ia_drq[1].ir_drq : ia->ia_drq[0].ir_drq;
843 1.1 brezak
844 1.1 brezak /*
845 1.1 brezak * Figure out our board rev, and see if we need to initialize the
846 1.1 brezak * mixer
847 1.1 brezak */
848 1.1 brezak
849 1.55 thorpej sc->sc_ic = ia->ia_ic;
850 1.44 augustss
851 1.87 kent delay(500);
852 1.1 brezak
853 1.112 nat mutex_spin_enter(&sc->sc_codec.sc_ad1848.sc_intr_lock);
854 1.107 jmcneill
855 1.87 kent c = bus_space_read_1(iot, ioh3, GUS_BOARD_REV);
856 1.1 brezak if (c != 0xff)
857 1.1 brezak sc->sc_revision = c;
858 1.1 brezak else
859 1.1 brezak sc->sc_revision = 0;
860 1.1 brezak
861 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
862 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
863 1.1 brezak
864 1.1 brezak gusreset(sc, GUS_MAX_VOICES); /* initialize all voices */
865 1.1 brezak gusreset(sc, GUS_MIN_VOICES); /* then set to just the ones we use */
866 1.112 nat mutex_spin_exit(&sc->sc_codec.sc_ad1848.sc_intr_lock);
867 1.1 brezak
868 1.1 brezak /*
869 1.1 brezak * Setup the IRQ and DRQ lines in software, using values from
870 1.1 brezak * config file
871 1.1 brezak */
872 1.1 brezak
873 1.1 brezak m = GUSMASK_LINE_IN|GUSMASK_LINE_OUT; /* disable all */
874 1.1 brezak
875 1.74 thorpej c = ((unsigned char) gus_irq_map[ia->ia_irq[0].ir_irq]) |
876 1.74 thorpej GUSMASK_BOTH_RQ;
877 1.1 brezak
878 1.93 christos if (sc->sc_playdrq != -1) {
879 1.93 christos if (sc->sc_recdrq == sc->sc_playdrq)
880 1.93 christos d = (unsigned char) (gus_drq_map[sc->sc_playdrq] |
881 1.93 christos GUSMASK_BOTH_RQ);
882 1.93 christos else if (sc->sc_recdrq != -1)
883 1.93 christos d = (unsigned char) (gus_drq_map[sc->sc_playdrq] |
884 1.93 christos gus_drq_map[sc->sc_recdrq] << 3);
885 1.93 christos }
886 1.93 christos if (d == -1)
887 1.93 christos printf("%s: WARNING: Cannot initialize drq\n",
888 1.109 chs device_xname(sc->sc_dev));
889 1.1 brezak
890 1.1 brezak /*
891 1.1 brezak * Program the IRQ and DMA channels on the GUS. Note that we hardwire
892 1.1 brezak * the GUS to only use one IRQ channel, but we give the user the
893 1.53 augustss * option of using two DMA channels (the other one given by the drq2
894 1.1 brezak * option in the config file). Two DMA channels are needed for full-
895 1.1 brezak * duplex operation.
896 1.1 brezak *
897 1.1 brezak * The order of these operations is very magical.
898 1.1 brezak */
899 1.1 brezak
900 1.43 augustss bus_space_write_1(iot, ioh1, GUS_REG_CONTROL, GUS_REG_IRQCTL);
901 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, m);
902 1.43 augustss bus_space_write_1(iot, ioh1, GUS_IRQCTL_CONTROL, 0x00);
903 1.43 augustss bus_space_write_1(iot, ioh1, 0x0f, 0x00);
904 1.1 brezak
905 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, m);
906 1.43 augustss bus_space_write_1(iot, ioh1, GUS_DMA_CONTROL, d | 0x80); /* magic reset? */
907 1.1 brezak
908 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, m | GUSMASK_CONTROL_SEL);
909 1.43 augustss bus_space_write_1(iot, ioh1, GUS_IRQ_CONTROL, c);
910 1.1 brezak
911 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, m);
912 1.43 augustss bus_space_write_1(iot, ioh1, GUS_DMA_CONTROL, d);
913 1.1 brezak
914 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, m | GUSMASK_CONTROL_SEL);
915 1.43 augustss bus_space_write_1(iot, ioh1, GUS_IRQ_CONTROL, c);
916 1.1 brezak
917 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, 0x00);
918 1.1 brezak
919 1.1 brezak /* enable line in, line out. leave mic disabled. */
920 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL,
921 1.1 brezak (m | GUSMASK_LATCHES) & ~(GUSMASK_LINE_OUT|GUSMASK_LINE_IN));
922 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, 0x00);
923 1.1 brezak
924 1.1 brezak sc->sc_mixcontrol =
925 1.1 brezak (m | GUSMASK_LATCHES) & ~(GUSMASK_LINE_OUT|GUSMASK_LINE_IN);
926 1.1 brezak
927 1.67 mycroft if (sc->sc_playdrq != -1) {
928 1.68 thorpej sc->sc_play_maxsize = isa_dmamaxsize(sc->sc_ic,
929 1.68 thorpej sc->sc_playdrq);
930 1.81 fvdl if (isa_drq_alloc(sc->sc_ic, sc->sc_playdrq) != 0) {
931 1.109 chs aprint_error_dev(sc->sc_dev, "can't reserve drq %d\n",
932 1.101 cegger sc->sc_playdrq);
933 1.107 jmcneill ad1848_destroy_locks(&sc->sc_codec.sc_ad1848);
934 1.81 fvdl return;
935 1.81 fvdl }
936 1.67 mycroft if (isa_dmamap_create(sc->sc_ic, sc->sc_playdrq,
937 1.107 jmcneill sc->sc_play_maxsize, BUS_DMA_WAITOK|BUS_DMA_ALLOCNOW)) {
938 1.110 msaitoh aprint_error_dev(sc->sc_dev,
939 1.110 msaitoh "can't create map for drq %d\n", sc->sc_playdrq);
940 1.107 jmcneill ad1848_destroy_locks(&sc->sc_codec.sc_ad1848);
941 1.67 mycroft return;
942 1.44 augustss }
943 1.67 mycroft }
944 1.67 mycroft if (sc->sc_recdrq != -1 && sc->sc_recdrq != sc->sc_playdrq) {
945 1.68 thorpej sc->sc_req_maxsize = isa_dmamaxsize(sc->sc_ic,
946 1.68 thorpej sc->sc_recdrq);
947 1.81 fvdl if (isa_drq_alloc(sc->sc_ic, sc->sc_recdrq) != 0) {
948 1.109 chs aprint_error_dev(sc->sc_dev, "can't reserve drq %d\n",
949 1.101 cegger sc->sc_recdrq);
950 1.107 jmcneill ad1848_destroy_locks(&sc->sc_codec.sc_ad1848);
951 1.81 fvdl return;
952 1.81 fvdl }
953 1.67 mycroft if (isa_dmamap_create(sc->sc_ic, sc->sc_recdrq,
954 1.107 jmcneill sc->sc_req_maxsize, BUS_DMA_WAITOK|BUS_DMA_ALLOCNOW)) {
955 1.110 msaitoh aprint_error_dev(sc->sc_dev,
956 1.110 msaitoh "can't create map for drq %d\n", sc->sc_recdrq);
957 1.107 jmcneill ad1848_destroy_locks(&sc->sc_codec.sc_ad1848);
958 1.67 mycroft return;
959 1.44 augustss }
960 1.1 brezak }
961 1.1 brezak
962 1.68 thorpej /* XXX WILL THIS ALWAYS WORK THE WAY THEY'RE OVERLAYED?! */
963 1.68 thorpej sc->sc_codec.sc_ic = sc->sc_ic;
964 1.68 thorpej
965 1.87 kent if (sc->sc_revision >= 5 && sc->sc_revision <= 9) {
966 1.87 kent sc->sc_flags |= GUS_MIXER_INSTALLED;
967 1.87 kent gus_init_ics2101(sc);
968 1.68 thorpej }
969 1.85 yamt hwif = &gus_hw_if;
970 1.68 thorpej if (sc->sc_revision >= 10)
971 1.85 yamt if (gus_init_cs4231(sc))
972 1.85 yamt hwif = &gusmax_hw_if;
973 1.68 thorpej
974 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
975 1.87 kent /*
976 1.87 kent * Check to see how much memory we have on this card; see if any
977 1.87 kent * "mirroring" occurs. We're assuming at least 256K already exists
978 1.87 kent * on the card; otherwise the initial probe would have failed
979 1.87 kent */
980 1.1 brezak
981 1.43 augustss guspoke(iot, ioh2, 0L, 0x00);
982 1.87 kent for (i = 1; i < 1024; i++) {
983 1.14 christos u_long loc;
984 1.1 brezak
985 1.1 brezak /*
986 1.1 brezak * See if we've run into mirroring yet
987 1.1 brezak */
988 1.1 brezak
989 1.43 augustss if (guspeek(iot, ioh2, 0L) != 0)
990 1.1 brezak break;
991 1.1 brezak
992 1.1 brezak loc = i << 10;
993 1.1 brezak
994 1.43 augustss guspoke(iot, ioh2, loc, 0xaa);
995 1.43 augustss if (guspeek(iot, ioh2, loc) != 0xaa)
996 1.1 brezak break;
997 1.1 brezak }
998 1.1 brezak
999 1.1 brezak sc->sc_dsize = i;
1000 1.1 brezak
1001 1.53 augustss /* The "official" (3.x) version number cannot easily be obtained.
1002 1.53 augustss * The revision register does not correspond to the minor number
1003 1.53 augustss * of the board version. Simply use the revision register as
1004 1.53 augustss * identification.
1005 1.53 augustss */
1006 1.83 itojun snprintf(gus_device.version, sizeof(gus_device.version), "%d",
1007 1.83 itojun sc->sc_revision);
1008 1.53 augustss
1009 1.109 chs printf("\n%s: Gravis UltraSound", device_xname(sc->sc_dev));
1010 1.53 augustss if (sc->sc_revision >= 10)
1011 1.53 augustss printf(" MAX");
1012 1.53 augustss else {
1013 1.53 augustss if (HAS_MIXER(sc))
1014 1.53 augustss printf(", mixer");
1015 1.53 augustss if (HAS_CODEC(sc))
1016 1.53 augustss printf(" with CODEC module");
1017 1.53 augustss }
1018 1.53 augustss printf(", %dKB memory\n", sc->sc_dsize);
1019 1.53 augustss
1020 1.53 augustss /* A GUS MAX should always have a CODEC installed */
1021 1.111 jakllsch if ((sc->sc_revision >= 10) && !(HAS_CODEC(sc)))
1022 1.87 kent printf("%s: WARNING: did not attach CODEC on MAX\n",
1023 1.109 chs device_xname(sc->sc_dev));
1024 1.1 brezak
1025 1.1 brezak /*
1026 1.1 brezak * Setup a default interrupt handler
1027 1.1 brezak */
1028 1.1 brezak
1029 1.74 thorpej sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
1030 1.108 mrg IST_EDGE, IPL_AUDIO, gusintr, sc /* sc->sc_gusdsp */);
1031 1.1 brezak
1032 1.1 brezak /*
1033 1.1 brezak * Set some default values
1034 1.79 wiz * XXX others start with 8kHz mono mu-law
1035 1.1 brezak */
1036 1.1 brezak
1037 1.1 brezak sc->sc_irate = sc->sc_orate = 44100;
1038 1.32 augustss sc->sc_encoding = AUDIO_ENCODING_SLINEAR_LE;
1039 1.1 brezak sc->sc_precision = 16;
1040 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].voccntl |= GUSMASK_DATA_SIZE16;
1041 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].voccntl |= GUSMASK_DATA_SIZE16;
1042 1.1 brezak sc->sc_channels = 1;
1043 1.1 brezak sc->sc_ogain = 340;
1044 1.1 brezak gus_commit_settings(sc);
1045 1.1 brezak
1046 1.1 brezak /*
1047 1.1 brezak * We always put the left channel full left & right channel
1048 1.1 brezak * full right.
1049 1.1 brezak * For mono playback, we set up both voices playing the same buffer.
1050 1.1 brezak */
1051 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT,
1052 1.110 msaitoh (unsigned char)GUS_VOICE_LEFT);
1053 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_PAN_POS);
1054 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, GUS_PAN_FULL_LEFT);
1055 1.43 augustss
1056 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT,
1057 1.110 msaitoh (unsigned char)GUS_VOICE_RIGHT);
1058 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_PAN_POS);
1059 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, GUS_PAN_FULL_RIGHT);
1060 1.1 brezak
1061 1.107 jmcneill /* set up buffer to hold the deinterleave, if necessary
1062 1.107 jmcneill for stereo output */
1063 1.107 jmcneill sc->sc_deintr_buf = kmem_alloc(GUS_MAX_BLOCKSIZE>>1, KM_SLEEP);
1064 1.107 jmcneill
1065 1.1 brezak /*
1066 1.1 brezak * Attach to the generic audio layer
1067 1.1 brezak */
1068 1.1 brezak
1069 1.85 yamt audio_attach_mi(hwif,
1070 1.109 chs HAS_CODEC(sc) ? (void *)&sc->sc_codec : (void *)sc, sc->sc_dev);
1071 1.1 brezak }
1072 1.1 brezak
1073 1.1 brezak int
1074 1.87 kent gusopen(void *addr, int flags)
1075 1.1 brezak {
1076 1.87 kent struct gus_softc *sc;
1077 1.1 brezak
1078 1.87 kent sc = addr;
1079 1.1 brezak DPRINTF(("gusopen() called\n"));
1080 1.1 brezak
1081 1.1 brezak if (sc->sc_flags & GUS_OPEN)
1082 1.1 brezak return EBUSY;
1083 1.1 brezak
1084 1.1 brezak /*
1085 1.1 brezak * Some initialization
1086 1.1 brezak */
1087 1.1 brezak
1088 1.1 brezak sc->sc_flags |= GUS_OPEN;
1089 1.1 brezak sc->sc_dmabuf = 0;
1090 1.1 brezak sc->sc_playbuf = -1;
1091 1.1 brezak sc->sc_bufcnt = 0;
1092 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].start_addr = GUS_MEM_OFFSET - 1;
1093 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].current_addr = GUS_MEM_OFFSET;
1094 1.1 brezak
1095 1.1 brezak if (HAS_CODEC(sc)) {
1096 1.62 jtk ad1848_open(&sc->sc_codec.sc_ad1848, flags);
1097 1.60 pk sc->sc_codec.sc_ad1848.mute[AD1848_AUX1_CHANNEL] = 0;
1098 1.60 pk
1099 1.60 pk /* turn on DAC output */
1100 1.60 pk ad1848_mute_channel(&sc->sc_codec.sc_ad1848,
1101 1.60 pk AD1848_AUX1_CHANNEL, 0);
1102 1.1 brezak if (flags & FREAD) {
1103 1.60 pk sc->sc_codec.sc_ad1848.mute[AD1848_MONO_CHANNEL] = 0;
1104 1.60 pk ad1848_mute_channel(&sc->sc_codec.sc_ad1848,
1105 1.60 pk AD1848_MONO_CHANNEL, 0);
1106 1.1 brezak }
1107 1.1 brezak } else if (flags & FREAD) {
1108 1.1 brezak /* enable/unmute the microphone */
1109 1.1 brezak if (HAS_MIXER(sc)) {
1110 1.1 brezak gusics_mic_mute(&sc->sc_mixer, 0);
1111 1.1 brezak } else
1112 1.1 brezak gus_mic_ctl(sc, SPKR_ON);
1113 1.1 brezak }
1114 1.1 brezak if (sc->sc_nbufs == 0)
1115 1.86 kent gus_round_blocksize(sc, GUS_BUFFER_MULTIPLE, /* default blksiz */
1116 1.86 kent 0, NULL); /* XXX */
1117 1.1 brezak return 0;
1118 1.1 brezak }
1119 1.1 brezak
1120 1.36 augustss int
1121 1.87 kent gusmaxopen(void *addr, int flags)
1122 1.36 augustss {
1123 1.87 kent struct ad1848_isa_softc *ac;
1124 1.87 kent
1125 1.87 kent ac = addr;
1126 1.62 jtk return gusopen(ac->sc_ad1848.parent, flags);
1127 1.36 augustss }
1128 1.36 augustss
1129 1.8 jtk STATIC void
1130 1.89 christos gus_deinterleave(struct gus_softc *sc, void *tbuf, int size)
1131 1.1 brezak {
1132 1.1 brezak /* deinterleave the stereo data. We can use sc->sc_deintr_buf
1133 1.1 brezak for scratch space. */
1134 1.38 augustss int i;
1135 1.1 brezak
1136 1.28 augustss if (size > sc->sc_blocksize) {
1137 1.28 augustss printf("gus: deinterleave %d > %d\n", size, sc->sc_blocksize);
1138 1.28 augustss return;
1139 1.28 augustss } else if (size < sc->sc_blocksize) {
1140 1.110 msaitoh DPRINTF(("gus: deinterleave %d < %d\n", size,
1141 1.110 msaitoh sc->sc_blocksize));
1142 1.28 augustss }
1143 1.28 augustss
1144 1.1 brezak /*
1145 1.1 brezak * size is in bytes.
1146 1.1 brezak */
1147 1.1 brezak if (sc->sc_precision == 16) {
1148 1.38 augustss u_short *dei = sc->sc_deintr_buf;
1149 1.89 christos u_short *sbuf = tbuf;
1150 1.1 brezak size >>= 1; /* bytecnt to shortcnt */
1151 1.1 brezak /* copy 2nd of each pair of samples to the staging area, while
1152 1.1 brezak compacting the 1st of each pair into the original area. */
1153 1.1 brezak for (i = 0; i < size/2-1; i++) {
1154 1.1 brezak dei[i] = sbuf[i*2+1];
1155 1.1 brezak sbuf[i+1] = sbuf[i*2+2];
1156 1.1 brezak }
1157 1.1 brezak /*
1158 1.1 brezak * this has copied one less sample than half of the
1159 1.1 brezak * buffer. The first sample of the 1st stream was
1160 1.1 brezak * already in place and didn't need copying.
1161 1.1 brezak * Therefore, we've moved all of the 1st stream's
1162 1.1 brezak * samples into place. We have one sample from 2nd
1163 1.1 brezak * stream in the last slot of original area, not
1164 1.1 brezak * copied to the staging area (But we don't need to!).
1165 1.1 brezak * Copy the remainder of the original stream into place.
1166 1.1 brezak */
1167 1.71 thorpej memcpy(&sbuf[size/2], dei, i * sizeof(short));
1168 1.1 brezak } else {
1169 1.38 augustss u_char *dei = sc->sc_deintr_buf;
1170 1.89 christos u_char *sbuf = tbuf;
1171 1.1 brezak for (i = 0; i < size/2-1; i++) {
1172 1.1 brezak dei[i] = sbuf[i*2+1];
1173 1.1 brezak sbuf[i+1] = sbuf[i*2+2];
1174 1.1 brezak }
1175 1.71 thorpej memcpy(&sbuf[size/2], dei, i);
1176 1.1 brezak }
1177 1.1 brezak }
1178 1.1 brezak
1179 1.1 brezak /*
1180 1.1 brezak * Actually output a buffer to the DSP chip
1181 1.1 brezak */
1182 1.1 brezak
1183 1.1 brezak int
1184 1.89 christos gusmax_dma_output(void *addr, void *tbuf, int size,
1185 1.87 kent void (*intr)(void *), void *arg)
1186 1.1 brezak {
1187 1.87 kent struct ad1848_isa_softc *ac;
1188 1.87 kent
1189 1.87 kent ac = addr;
1190 1.89 christos return gus_dma_output(ac->sc_ad1848.parent, tbuf, size, intr, arg);
1191 1.1 brezak }
1192 1.1 brezak
1193 1.1 brezak /*
1194 1.107 jmcneill * called from interrupt handler.
1195 1.1 brezak */
1196 1.1 brezak void
1197 1.87 kent stereo_dmaintr(void *arg)
1198 1.1 brezak {
1199 1.87 kent struct gus_softc *sc;
1200 1.87 kent struct stereo_dma_intr *sa;
1201 1.1 brezak
1202 1.87 kent DMAPRINTF(("stereo_dmaintr"));
1203 1.87 kent sc = arg;
1204 1.87 kent sa = &sc->sc_stereo;
1205 1.1 brezak
1206 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
1207 1.107 jmcneill
1208 1.87 kent /*
1209 1.87 kent * Put other half in its place, then call the real interrupt routine :)
1210 1.87 kent */
1211 1.1 brezak
1212 1.87 kent sc->sc_dmaoutintr = sa->intr;
1213 1.87 kent sc->sc_outarg = sa->arg;
1214 1.1 brezak
1215 1.1 brezak #ifdef GUSPLAYDEBUG
1216 1.87 kent if (gusstats) {
1217 1.87 kent microtime(&dmarecords[dmarecord_index].tv);
1218 1.87 kent dmarecords[dmarecord_index].gusaddr = sa->dmabuf;
1219 1.87 kent dmarecords[dmarecord_index].bsdaddr = sa->buffer;
1220 1.87 kent dmarecords[dmarecord_index].count = sa->size;
1221 1.87 kent dmarecords[dmarecord_index].channel = 1;
1222 1.87 kent dmarecords[dmarecord_index].direction = 1;
1223 1.87 kent dmarecord_index = (dmarecord_index + 1) % NDMARECS;
1224 1.87 kent }
1225 1.1 brezak #endif
1226 1.1 brezak
1227 1.97 christos gusdmaout(sc, sa->flags, sa->dmabuf, (void *) sa->buffer, sa->size);
1228 1.1 brezak
1229 1.87 kent sa->flags = 0;
1230 1.87 kent sa->dmabuf = 0;
1231 1.87 kent sa->buffer = 0;
1232 1.87 kent sa->size = 0;
1233 1.87 kent sa->intr = 0;
1234 1.87 kent sa->arg = 0;
1235 1.1 brezak }
1236 1.1 brezak
1237 1.1 brezak /*
1238 1.1 brezak * Start up DMA output to the card.
1239 1.1 brezak */
1240 1.1 brezak int
1241 1.89 christos gus_dma_output(void *addr, void *tbuf, int size,
1242 1.87 kent void (*intr)(void *), void *arg)
1243 1.1 brezak {
1244 1.87 kent struct gus_softc *sc;
1245 1.87 kent u_char *buffer;
1246 1.1 brezak u_long boarddma;
1247 1.14 christos int flags;
1248 1.1 brezak
1249 1.89 christos DMAPRINTF(("gus_dma_output %d @ %p\n", size, tbuf));
1250 1.87 kent sc = addr;
1251 1.89 christos buffer = tbuf;
1252 1.1 brezak
1253 1.1 brezak if (size != sc->sc_blocksize) {
1254 1.87 kent DPRINTF(("gus_dma_output reqsize %d not sc_blocksize %d\n",
1255 1.1 brezak size, sc->sc_blocksize));
1256 1.87 kent return EINVAL;
1257 1.1 brezak }
1258 1.1 brezak
1259 1.1 brezak flags = GUSMASK_DMA_WRITE;
1260 1.1 brezak if (sc->sc_precision == 16)
1261 1.87 kent flags |= GUSMASK_DMA_DATA_SIZE;
1262 1.1 brezak if (sc->sc_encoding == AUDIO_ENCODING_ULAW ||
1263 1.39 augustss sc->sc_encoding == AUDIO_ENCODING_ALAW ||
1264 1.29 jtk sc->sc_encoding == AUDIO_ENCODING_ULINEAR_BE ||
1265 1.24 augustss sc->sc_encoding == AUDIO_ENCODING_ULINEAR_LE)
1266 1.87 kent flags |= GUSMASK_DMA_INVBIT;
1267 1.1 brezak
1268 1.1 brezak if (sc->sc_channels == 2) {
1269 1.1 brezak if (sc->sc_precision == 16) {
1270 1.1 brezak if (size & 3) {
1271 1.1 brezak DPRINTF(("gus_dma_output: unpaired 16bit samples"));
1272 1.1 brezak size &= 3;
1273 1.1 brezak }
1274 1.1 brezak } else if (size & 1) {
1275 1.1 brezak DPRINTF(("gus_dma_output: unpaired samples"));
1276 1.1 brezak size &= 1;
1277 1.1 brezak }
1278 1.1 brezak if (size == 0)
1279 1.1 brezak return 0;
1280 1.28 augustss
1281 1.28 augustss gus_deinterleave(sc, (void *)buffer, size);
1282 1.28 augustss
1283 1.1 brezak size >>= 1;
1284 1.1 brezak
1285 1.87 kent boarddma = size * sc->sc_dmabuf + GUS_MEM_OFFSET;
1286 1.1 brezak
1287 1.1 brezak sc->sc_stereo.intr = intr;
1288 1.1 brezak sc->sc_stereo.arg = arg;
1289 1.1 brezak sc->sc_stereo.size = size;
1290 1.1 brezak sc->sc_stereo.dmabuf = boarddma + GUS_LEFT_RIGHT_OFFSET;
1291 1.1 brezak sc->sc_stereo.buffer = buffer + size;
1292 1.1 brezak sc->sc_stereo.flags = flags;
1293 1.1 brezak if (gus_dostereo) {
1294 1.87 kent intr = stereo_dmaintr;
1295 1.87 kent arg = sc;
1296 1.1 brezak }
1297 1.1 brezak } else
1298 1.1 brezak boarddma = size * sc->sc_dmabuf + GUS_MEM_OFFSET;
1299 1.1 brezak
1300 1.1 brezak
1301 1.1 brezak sc->sc_flags |= GUS_LOCKED;
1302 1.1 brezak sc->sc_dmaoutintr = intr;
1303 1.1 brezak sc->sc_outarg = arg;
1304 1.1 brezak
1305 1.1 brezak #ifdef GUSPLAYDEBUG
1306 1.1 brezak if (gusstats) {
1307 1.87 kent microtime(&dmarecords[dmarecord_index].tv);
1308 1.87 kent dmarecords[dmarecord_index].gusaddr = boarddma;
1309 1.87 kent dmarecords[dmarecord_index].bsdaddr = buffer;
1310 1.87 kent dmarecords[dmarecord_index].count = size;
1311 1.87 kent dmarecords[dmarecord_index].channel = 0;
1312 1.87 kent dmarecords[dmarecord_index].direction = 1;
1313 1.87 kent dmarecord_index = (dmarecord_index + 1) % NDMARECS;
1314 1.1 brezak }
1315 1.1 brezak #endif
1316 1.1 brezak
1317 1.97 christos gusdmaout(sc, flags, boarddma, (void *) buffer, size);
1318 1.1 brezak
1319 1.1 brezak return 0;
1320 1.1 brezak }
1321 1.1 brezak
1322 1.1 brezak void
1323 1.87 kent gusmax_close(void *addr)
1324 1.1 brezak {
1325 1.87 kent struct ad1848_isa_softc *ac;
1326 1.87 kent struct gus_softc *sc;
1327 1.87 kent
1328 1.87 kent ac = addr;
1329 1.87 kent sc = ac->sc_ad1848.parent;
1330 1.14 christos #if 0
1331 1.54 augustss ac->mute[AD1848_AUX1_CHANNEL] = MUTE_ALL;
1332 1.54 augustss ad1848_mute_channel(ac, MUTE_ALL); /* turn off DAC output */
1333 1.14 christos #endif
1334 1.62 jtk ad1848_close(&ac->sc_ad1848);
1335 1.1 brezak gusclose(sc);
1336 1.1 brezak }
1337 1.1 brezak
1338 1.1 brezak /*
1339 1.107 jmcneill * Close out device stuff.
1340 1.1 brezak */
1341 1.1 brezak void
1342 1.87 kent gusclose(void *addr)
1343 1.1 brezak {
1344 1.87 kent struct gus_softc *sc;
1345 1.1 brezak
1346 1.87 kent sc = addr;
1347 1.87 kent DPRINTF(("gus_close: sc=%p\n", sc));
1348 1.1 brezak
1349 1.1 brezak
1350 1.1 brezak /* if (sc->sc_flags & GUS_DMAOUT_ACTIVE) */ {
1351 1.1 brezak gus_halt_out_dma(sc);
1352 1.1 brezak }
1353 1.1 brezak /* if (sc->sc_flags & GUS_DMAIN_ACTIVE) */ {
1354 1.1 brezak gus_halt_in_dma(sc);
1355 1.1 brezak }
1356 1.1 brezak sc->sc_flags &= ~(GUS_OPEN|GUS_LOCKED|GUS_DMAOUT_ACTIVE|GUS_DMAIN_ACTIVE);
1357 1.1 brezak
1358 1.1 brezak /* turn off speaker, etc. */
1359 1.1 brezak
1360 1.1 brezak /* make sure the voices shut up: */
1361 1.1 brezak gus_stop_voice(sc, GUS_VOICE_LEFT, 1);
1362 1.1 brezak gus_stop_voice(sc, GUS_VOICE_RIGHT, 0);
1363 1.1 brezak }
1364 1.1 brezak
1365 1.1 brezak /*
1366 1.1 brezak * Service interrupts. Farm them off to helper routines if we are using the
1367 1.1 brezak * GUS for simple playback/record
1368 1.1 brezak */
1369 1.1 brezak
1370 1.1 brezak #ifdef DIAGNOSTIC
1371 1.1 brezak int gusintrcnt;
1372 1.1 brezak int gusdmaintrcnt;
1373 1.1 brezak int gusvocintrcnt;
1374 1.1 brezak #endif
1375 1.1 brezak
1376 1.1 brezak int
1377 1.87 kent gusintr(void *arg)
1378 1.1 brezak {
1379 1.87 kent struct gus_softc *sc;
1380 1.87 kent bus_space_tag_t iot;
1381 1.87 kent bus_space_handle_t ioh1;
1382 1.87 kent bus_space_handle_t ioh2;
1383 1.1 brezak unsigned char intr;
1384 1.87 kent int retval;
1385 1.1 brezak
1386 1.1 brezak DPRINTF(("gusintr\n"));
1387 1.87 kent sc = arg;
1388 1.87 kent iot = sc->sc_iot;
1389 1.87 kent ioh1 = sc->sc_ioh1;
1390 1.87 kent ioh2 = sc->sc_ioh2;
1391 1.87 kent retval = 0;
1392 1.1 brezak #ifdef DIAGNOSTIC
1393 1.1 brezak gusintrcnt++;
1394 1.1 brezak #endif
1395 1.107 jmcneill
1396 1.107 jmcneill mutex_spin_enter(&sc->sc_codec.sc_ad1848.sc_intr_lock);
1397 1.107 jmcneill
1398 1.1 brezak if (HAS_CODEC(sc))
1399 1.60 pk retval = ad1848_isa_intr(&sc->sc_codec);
1400 1.110 msaitoh if ((intr = bus_space_read_1(iot, ioh1, GUS_IRQ_STATUS))
1401 1.110 msaitoh & GUSMASK_IRQ_DMATC) {
1402 1.80 wiz DMAPRINTF(("gusintr DMA flags=%x\n", sc->sc_flags));
1403 1.1 brezak #ifdef DIAGNOSTIC
1404 1.1 brezak gusdmaintrcnt++;
1405 1.1 brezak #endif
1406 1.1 brezak retval += gus_dmaout_intr(sc);
1407 1.1 brezak if (sc->sc_flags & GUS_DMAIN_ACTIVE) {
1408 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
1409 1.87 kent intr = bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
1410 1.87 kent if (intr & GUSMASK_SAMPLE_DMATC) {
1411 1.87 kent retval += gus_dmain_intr(sc);
1412 1.87 kent }
1413 1.1 brezak }
1414 1.1 brezak }
1415 1.1 brezak if (intr & (GUSMASK_IRQ_VOICE | GUSMASK_IRQ_VOLUME)) {
1416 1.1 brezak DMAPRINTF(("gusintr voice flags=%x\n", sc->sc_flags));
1417 1.1 brezak #ifdef DIAGNOSTIC
1418 1.1 brezak gusvocintrcnt++;
1419 1.1 brezak #endif
1420 1.1 brezak retval += gus_voice_intr(sc);
1421 1.1 brezak }
1422 1.107 jmcneill
1423 1.107 jmcneill mutex_spin_exit(&sc->sc_codec.sc_ad1848.sc_intr_lock);
1424 1.107 jmcneill
1425 1.1 brezak return retval;
1426 1.1 brezak }
1427 1.1 brezak
1428 1.1 brezak int gus_bufcnt[GUS_MEM_FOR_BUFFERS / GUS_BUFFER_MULTIPLE];
1429 1.1 brezak int gus_restart; /* how many restarts? */
1430 1.1 brezak int gus_stops; /* how many times did voice stop? */
1431 1.1 brezak int gus_falsestops; /* stopped but not done? */
1432 1.1 brezak int gus_continues;
1433 1.1 brezak
1434 1.1 brezak struct playcont {
1435 1.1 brezak struct timeval tv;
1436 1.1 brezak u_int playbuf;
1437 1.1 brezak u_int dmabuf;
1438 1.1 brezak u_char bufcnt;
1439 1.1 brezak u_char vaction;
1440 1.1 brezak u_char voccntl;
1441 1.1 brezak u_char volcntl;
1442 1.1 brezak u_long curaddr;
1443 1.1 brezak u_long endaddr;
1444 1.1 brezak } playstats[NDMARECS];
1445 1.1 brezak
1446 1.1 brezak int playcntr;
1447 1.1 brezak
1448 1.8 jtk STATIC void
1449 1.87 kent gus_dmaout_timeout(void *arg)
1450 1.1 brezak {
1451 1.87 kent struct gus_softc *sc;
1452 1.87 kent bus_space_tag_t iot;
1453 1.87 kent bus_space_handle_t ioh2;
1454 1.87 kent
1455 1.87 kent sc = arg;
1456 1.87 kent iot = sc->sc_iot;
1457 1.87 kent ioh2 = sc->sc_ioh2;
1458 1.109 chs printf("%s: dmaout timeout\n", device_xname(sc->sc_dev));
1459 1.107 jmcneill
1460 1.87 kent /*
1461 1.87 kent * Stop any DMA.
1462 1.87 kent */
1463 1.107 jmcneill mutex_spin_enter(&sc->sc_codec.sc_ad1848.sc_intr_lock);
1464 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
1465 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0);
1466 1.14 christos #if 0
1467 1.87 kent /* XXX we will dmadone below? */
1468 1.109 chs isa_dmaabort(device_parent(sc->sc_dev), sc->sc_playdrq);
1469 1.14 christos #endif
1470 1.87 kent
1471 1.87 kent gus_dmaout_dointr(sc);
1472 1.107 jmcneill mutex_spin_exit(&sc->sc_codec.sc_ad1848.sc_intr_lock);
1473 1.1 brezak }
1474 1.1 brezak
1475 1.1 brezak
1476 1.1 brezak /*
1477 1.1 brezak * Service DMA interrupts. This routine will only get called if we're doing
1478 1.1 brezak * a DMA transfer for playback/record requests from the audio layer.
1479 1.1 brezak */
1480 1.1 brezak
1481 1.8 jtk STATIC int
1482 1.87 kent gus_dmaout_intr(struct gus_softc *sc)
1483 1.1 brezak {
1484 1.87 kent bus_space_tag_t iot;
1485 1.87 kent bus_space_handle_t ioh2;
1486 1.1 brezak
1487 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
1488 1.107 jmcneill
1489 1.87 kent iot = sc->sc_iot;
1490 1.87 kent ioh2 = sc->sc_ioh2;
1491 1.1 brezak /*
1492 1.1 brezak * If we got a DMA transfer complete from the GUS DRAM, then deal
1493 1.1 brezak * with it.
1494 1.1 brezak */
1495 1.1 brezak
1496 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
1497 1.87 kent if (bus_space_read_1(iot, ioh2, GUS_DATA_HIGH) & GUSMASK_DMA_IRQPEND) {
1498 1.87 kent callout_stop(&sc->sc_dmaout_ch);
1499 1.87 kent gus_dmaout_dointr(sc);
1500 1.87 kent return 1;
1501 1.1 brezak }
1502 1.1 brezak return 0;
1503 1.1 brezak }
1504 1.1 brezak
1505 1.8 jtk STATIC void
1506 1.87 kent gus_dmaout_dointr(struct gus_softc *sc)
1507 1.1 brezak {
1508 1.87 kent bus_space_tag_t iot;
1509 1.87 kent bus_space_handle_t ioh2;
1510 1.1 brezak
1511 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
1512 1.107 jmcneill
1513 1.87 kent iot = sc->sc_iot;
1514 1.87 kent ioh2 = sc->sc_ioh2;
1515 1.1 brezak /* sc->sc_dmaoutcnt - 1 because DMA controller counts from zero?. */
1516 1.87 kent isa_dmadone(sc->sc_ic, sc->sc_playdrq);
1517 1.1 brezak sc->sc_flags &= ~GUS_DMAOUT_ACTIVE; /* pending DMA is done */
1518 1.87 kent DMAPRINTF(("gus_dmaout_dointr %d @ %p\n", sc->sc_dmaoutcnt,
1519 1.1 brezak sc->sc_dmaoutaddr));
1520 1.1 brezak
1521 1.1 brezak /*
1522 1.1 brezak * to prevent clicking, we need to copy last sample
1523 1.1 brezak * from last buffer to scratch area just before beginning of
1524 1.1 brezak * buffer. However, if we're doing formats that are converted by
1525 1.1 brezak * the card during the DMA process, we need to pick up the converted
1526 1.1 brezak * byte rather than the one we have in memory.
1527 1.1 brezak */
1528 1.1 brezak if (sc->sc_dmabuf == sc->sc_nbufs - 1) {
1529 1.87 kent int i;
1530 1.87 kent switch (sc->sc_encoding) {
1531 1.87 kent case AUDIO_ENCODING_SLINEAR_LE:
1532 1.87 kent case AUDIO_ENCODING_SLINEAR_BE:
1533 1.87 kent if (sc->sc_precision == 8)
1534 1.87 kent goto byte;
1535 1.87 kent /* we have the native format */
1536 1.87 kent for (i = 1; i <= 2; i++)
1537 1.87 kent guspoke(iot, ioh2, sc->sc_gusaddr -
1538 1.87 kent (sc->sc_nbufs - 1) * sc->sc_chanblocksize - i,
1539 1.87 kent sc->sc_dmaoutaddr[sc->sc_dmaoutcnt-i]);
1540 1.87 kent break;
1541 1.87 kent case AUDIO_ENCODING_ULINEAR_LE:
1542 1.87 kent case AUDIO_ENCODING_ULINEAR_BE:
1543 1.87 kent guspoke(iot, ioh2, sc->sc_gusaddr -
1544 1.87 kent (sc->sc_nbufs - 1) * sc->sc_chanblocksize - 2,
1545 1.87 kent guspeek(iot, ioh2,
1546 1.87 kent sc->sc_gusaddr + sc->sc_chanblocksize - 2));
1547 1.114 mrg /* FALLTHROUGH */
1548 1.87 kent case AUDIO_ENCODING_ALAW:
1549 1.87 kent case AUDIO_ENCODING_ULAW:
1550 1.87 kent byte:
1551 1.87 kent /* we need to fetch the translated byte, then stuff it. */
1552 1.87 kent guspoke(iot, ioh2, sc->sc_gusaddr -
1553 1.87 kent (sc->sc_nbufs - 1) * sc->sc_chanblocksize - 1,
1554 1.87 kent guspeek(iot, ioh2,
1555 1.87 kent sc->sc_gusaddr + sc->sc_chanblocksize - 1));
1556 1.87 kent break;
1557 1.87 kent }
1558 1.1 brezak }
1559 1.1 brezak /*
1560 1.1 brezak * If this is the first half of stereo, "ignore" this one
1561 1.1 brezak * and copy out the second half.
1562 1.1 brezak */
1563 1.1 brezak if (sc->sc_dmaoutintr == stereo_dmaintr) {
1564 1.87 kent (*sc->sc_dmaoutintr)(sc->sc_outarg);
1565 1.87 kent return;
1566 1.1 brezak }
1567 1.1 brezak /*
1568 1.1 brezak * If the voice is stopped, then start it. Reset the loop
1569 1.1 brezak * and roll bits. Call the audio layer routine, since if
1570 1.1 brezak * we're starting a stopped voice, that means that the next
1571 1.1 brezak * buffer can be filled
1572 1.1 brezak */
1573 1.1 brezak
1574 1.1 brezak sc->sc_flags &= ~GUS_LOCKED;
1575 1.1 brezak if (sc->sc_voc[GUS_VOICE_LEFT].voccntl &
1576 1.1 brezak GUSMASK_VOICE_STOPPED) {
1577 1.87 kent if (sc->sc_flags & GUS_PLAYING) {
1578 1.109 chs printf("%s: playing yet stopped?\n", device_xname(sc->sc_dev));
1579 1.87 kent }
1580 1.87 kent sc->sc_bufcnt++; /* another yet to be played */
1581 1.87 kent gus_start_playing(sc, sc->sc_dmabuf);
1582 1.87 kent gus_restart++;
1583 1.1 brezak } else {
1584 1.1 brezak /*
1585 1.87 kent * set the sound action based on which buffer we
1586 1.87 kent * just transferred. If we just transferred buffer 0
1587 1.87 kent * we want the sound to loop when it gets to the nth
1588 1.87 kent * buffer; if we just transferred
1589 1.87 kent * any other buffer, we want the sound to roll over
1590 1.87 kent * at least one more time. The voice interrupt
1591 1.87 kent * handlers will take care of accounting &
1592 1.87 kent * setting control bits if it's not caught up to us
1593 1.87 kent * yet.
1594 1.1 brezak */
1595 1.87 kent if (++sc->sc_bufcnt == 2) {
1596 1.87 kent /*
1597 1.88 perry * XXX
1598 1.87 kent * If we're too slow in reaction here,
1599 1.87 kent * the voice could be just approaching the
1600 1.87 kent * end of its run. It should be set to stop,
1601 1.87 kent * so these adjustments might not DTRT.
1602 1.87 kent */
1603 1.87 kent if (sc->sc_dmabuf == 0 &&
1604 1.87 kent sc->sc_playbuf == sc->sc_nbufs - 1) {
1605 1.89 christos /* player is just at the last tbuf, we're at the
1606 1.87 kent first. Turn on looping, turn off rolling. */
1607 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].voccntl |= GUSMASK_LOOP_ENABLE;
1608 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].volcntl &= ~GUSMASK_VOICE_ROLL;
1609 1.87 kent playstats[playcntr].vaction = 3;
1610 1.87 kent } else {
1611 1.89 christos /* player is at previous tbuf:
1612 1.87 kent turn on rolling, turn off looping */
1613 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].voccntl &= ~GUSMASK_LOOP_ENABLE;
1614 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].volcntl |= GUSMASK_VOICE_ROLL;
1615 1.87 kent playstats[playcntr].vaction = 4;
1616 1.87 kent }
1617 1.1 brezak #ifdef GUSPLAYDEBUG
1618 1.87 kent if (gusstats) {
1619 1.87 kent microtime(&playstats[playcntr].tv);
1620 1.87 kent playstats[playcntr].endaddr
1621 1.87 kent = sc->sc_voc[GUS_VOICE_LEFT].end_addr;
1622 1.87 kent playstats[playcntr].voccntl
1623 1.87 kent = sc->sc_voc[GUS_VOICE_LEFT].voccntl;
1624 1.87 kent playstats[playcntr].volcntl
1625 1.87 kent = sc->sc_voc[GUS_VOICE_LEFT].volcntl;
1626 1.87 kent playstats[playcntr].playbuf = sc->sc_playbuf;
1627 1.87 kent playstats[playcntr].dmabuf = sc->sc_dmabuf;
1628 1.87 kent playstats[playcntr].bufcnt = sc->sc_bufcnt;
1629 1.87 kent playstats[playcntr].curaddr
1630 1.87 kent = gus_get_curaddr(sc, GUS_VOICE_LEFT);
1631 1.87 kent playcntr = (playcntr + 1) % NDMARECS;
1632 1.87 kent }
1633 1.87 kent #endif
1634 1.87 kent bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, GUS_VOICE_LEFT);
1635 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
1636 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
1637 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].voccntl);
1638 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
1639 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
1640 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].volcntl);
1641 1.1 brezak }
1642 1.1 brezak }
1643 1.1 brezak gus_bufcnt[sc->sc_bufcnt-1]++;
1644 1.1 brezak /*
1645 1.1 brezak * flip to the next DMA buffer
1646 1.1 brezak */
1647 1.1 brezak
1648 1.106 mrg sc->sc_dmabuf = (sc->sc_dmabuf + 1) % sc->sc_nbufs;
1649 1.1 brezak /*
1650 1.1 brezak * See comments below about DMA admission control strategy.
1651 1.1 brezak * We can call the upper level here if we have an
1652 1.1 brezak * idle buffer (not currently playing) to DMA into.
1653 1.1 brezak */
1654 1.1 brezak if (sc->sc_dmaoutintr && sc->sc_bufcnt < sc->sc_nbufs) {
1655 1.87 kent /* clean out to prevent double calls */
1656 1.87 kent void (*pfunc)(void *);
1657 1.87 kent void *arg;
1658 1.87 kent
1659 1.87 kent pfunc = sc->sc_dmaoutintr;
1660 1.87 kent arg = sc->sc_outarg;
1661 1.87 kent sc->sc_outarg = 0;
1662 1.87 kent sc->sc_dmaoutintr = 0;
1663 1.87 kent (*pfunc)(arg);
1664 1.1 brezak }
1665 1.1 brezak }
1666 1.1 brezak
1667 1.1 brezak /*
1668 1.1 brezak * Service voice interrupts
1669 1.1 brezak */
1670 1.1 brezak
1671 1.8 jtk STATIC int
1672 1.87 kent gus_voice_intr(struct gus_softc *sc)
1673 1.1 brezak {
1674 1.87 kent bus_space_tag_t iot;
1675 1.87 kent bus_space_handle_t ioh2;
1676 1.87 kent int ignore, voice, rval;
1677 1.1 brezak unsigned char intr, status;
1678 1.1 brezak
1679 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
1680 1.107 jmcneill
1681 1.87 kent iot = sc->sc_iot;
1682 1.87 kent ioh2 = sc->sc_ioh2;
1683 1.87 kent ignore = 0;
1684 1.87 kent rval = 0;
1685 1.1 brezak /*
1686 1.1 brezak * The point of this may not be obvious at first. A voice can
1687 1.1 brezak * interrupt more than once; according to the GUS SDK we are supposed
1688 1.1 brezak * to ignore multiple interrupts for the same voice.
1689 1.1 brezak */
1690 1.1 brezak
1691 1.87 kent while (1) {
1692 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_IRQ_STATUS);
1693 1.43 augustss intr = bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
1694 1.1 brezak
1695 1.1 brezak if ((intr & (GUSMASK_WIRQ_VOLUME | GUSMASK_WIRQ_VOICE))
1696 1.1 brezak == (GUSMASK_WIRQ_VOLUME | GUSMASK_WIRQ_VOICE))
1697 1.1 brezak /*
1698 1.1 brezak * No more interrupts, time to return
1699 1.1 brezak */
1700 1.87 kent return rval;
1701 1.1 brezak
1702 1.1 brezak if ((intr & GUSMASK_WIRQ_VOICE) == 0) {
1703 1.1 brezak
1704 1.87 kent /*
1705 1.87 kent * We've got a voice interrupt. Ignore previous
1706 1.87 kent * interrupts by the same voice.
1707 1.87 kent */
1708 1.1 brezak
1709 1.87 kent rval = 1;
1710 1.87 kent voice = intr & GUSMASK_WIRQ_VOICEMASK;
1711 1.1 brezak
1712 1.87 kent if ((1 << voice) & ignore)
1713 1.87 kent break;
1714 1.1 brezak
1715 1.87 kent ignore |= 1 << voice;
1716 1.1 brezak
1717 1.1 brezak /*
1718 1.87 kent * If the voice is stopped, then force it to stop
1719 1.87 kent * (this stops it from continuously generating IRQs)
1720 1.1 brezak */
1721 1.87 kent
1722 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL+0x80);
1723 1.87 kent status = bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
1724 1.87 kent if (status & GUSMASK_VOICE_STOPPED) {
1725 1.87 kent if (voice != GUS_VOICE_LEFT) {
1726 1.110 msaitoh DMAPRINTF(("%s: spurious voice %d "
1727 1.110 msaitoh "stop?\n",
1728 1.110 msaitoh device_xname(sc->sc_dev), voice));
1729 1.87 kent gus_stop_voice(sc, voice, 0);
1730 1.87 kent continue;
1731 1.87 kent }
1732 1.87 kent gus_stop_voice(sc, voice, 1);
1733 1.87 kent /* also kill right voice */
1734 1.87 kent gus_stop_voice(sc, GUS_VOICE_RIGHT, 0);
1735 1.87 kent sc->sc_bufcnt--; /* it finished a buffer */
1736 1.87 kent if (sc->sc_bufcnt > 0) {
1737 1.87 kent /*
1738 1.87 kent * probably a race to get here: the
1739 1.87 kent * voice stopped while the DMA code was
1740 1.87 kent * just trying to get the next buffer
1741 1.87 kent * in place. Start the voice again.
1742 1.87 kent */
1743 1.110 msaitoh printf("%s: stopped voice not drained?"
1744 1.110 msaitoh " (%x)\n",
1745 1.110 msaitoh device_xname(sc->sc_dev),
1746 1.110 msaitoh sc->sc_bufcnt);
1747 1.87 kent gus_falsestops++;
1748 1.87 kent
1749 1.110 msaitoh sc->sc_playbuf = (sc->sc_playbuf + 1)
1750 1.110 msaitoh % sc->sc_nbufs;
1751 1.87 kent gus_start_playing(sc, sc->sc_playbuf);
1752 1.87 kent } else if (sc->sc_bufcnt < 0) {
1753 1.110 msaitoh panic("%s: negative bufcnt in stopped "
1754 1.110 msaitoh "voice", device_xname(sc->sc_dev));
1755 1.87 kent } else {
1756 1.87 kent sc->sc_playbuf = -1; /* none are active */
1757 1.87 kent gus_stops++;
1758 1.87 kent }
1759 1.87 kent /* fall through to callback and admit another
1760 1.87 kent buffer.... */
1761 1.87 kent } else if (sc->sc_bufcnt != 0) {
1762 1.8 jtk /*
1763 1.87 kent * This should always be taken if the voice
1764 1.87 kent * is not stopped.
1765 1.8 jtk */
1766 1.87 kent gus_continues++;
1767 1.87 kent if (gus_continue_playing(sc, voice)) {
1768 1.87 kent /*
1769 1.87 kent * we shouldn't have continued--active
1770 1.87 kent * DMA is in the way in the ring, for
1771 1.87 kent * some as-yet undebugged reason.
1772 1.87 kent */
1773 1.87 kent gus_stop_voice(sc, GUS_VOICE_LEFT, 1);
1774 1.87 kent /* also kill right voice */
1775 1.87 kent gus_stop_voice(sc, GUS_VOICE_RIGHT, 0);
1776 1.87 kent sc->sc_playbuf = -1;
1777 1.87 kent gus_stops++;
1778 1.87 kent }
1779 1.8 jtk }
1780 1.87 kent /*
1781 1.87 kent * call the upper level to send on down another
1782 1.87 kent * block. We do admission rate control as follows:
1783 1.87 kent *
1784 1.87 kent * When starting up output (in the first N
1785 1.87 kent * blocks), call the upper layer after the DMA is
1786 1.87 kent * complete (see above in gus_dmaout_intr()).
1787 1.87 kent *
1788 1.87 kent * When output is already in progress and we have
1789 1.87 kent * no more GUS buffers to use for DMA, the DMA
1790 1.87 kent * output routines do not call the upper layer.
1791 1.87 kent * Instead, we call the DMA completion routine
1792 1.87 kent * here, after the voice interrupts indicating
1793 1.87 kent * that it's finished with a buffer.
1794 1.87 kent *
1795 1.87 kent * However, don't call anything here if the DMA
1796 1.87 kent * output flag is set, (which shouldn't happen)
1797 1.87 kent * because we'll squish somebody else's DMA if
1798 1.87 kent * that's the case. When DMA is done, it will
1799 1.87 kent * call back if there is a spare buffer.
1800 1.87 kent */
1801 1.87 kent if (sc->sc_dmaoutintr && !(sc->sc_flags & GUS_LOCKED)) {
1802 1.87 kent if (sc->sc_dmaoutintr == stereo_dmaintr)
1803 1.87 kent printf("gusdmaout botch?\n");
1804 1.87 kent else {
1805 1.87 kent /* clean out to avoid double calls */
1806 1.87 kent void (*pfunc)(void *);
1807 1.87 kent void *arg;
1808 1.87 kent
1809 1.87 kent pfunc = sc->sc_dmaoutintr;
1810 1.87 kent arg = sc->sc_outarg;
1811 1.87 kent sc->sc_outarg = 0;
1812 1.87 kent sc->sc_dmaoutintr = 0;
1813 1.87 kent (*pfunc)(arg);
1814 1.87 kent }
1815 1.1 brezak }
1816 1.1 brezak }
1817 1.1 brezak
1818 1.1 brezak /*
1819 1.1 brezak * Ignore other interrupts for now
1820 1.1 brezak */
1821 1.1 brezak }
1822 1.14 christos return 0;
1823 1.1 brezak }
1824 1.1 brezak
1825 1.87 kent /*
1826 1.87 kent * Start the voices playing, with buffer BUFNO.
1827 1.87 kent */
1828 1.8 jtk STATIC void
1829 1.87 kent gus_start_playing(struct gus_softc *sc, int bufno)
1830 1.1 brezak {
1831 1.87 kent bus_space_tag_t iot;
1832 1.87 kent bus_space_handle_t ioh2;
1833 1.1 brezak
1834 1.87 kent iot = sc->sc_iot;
1835 1.87 kent ioh2 = sc->sc_ioh2;
1836 1.43 augustss /*
1837 1.43 augustss * Loop or roll if we have buffers ready.
1838 1.43 augustss */
1839 1.1 brezak
1840 1.43 augustss if (sc->sc_bufcnt == 1) {
1841 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].voccntl &= ~(GUSMASK_LOOP_ENABLE);
1842 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].volcntl &= ~(GUSMASK_VOICE_ROLL);
1843 1.1 brezak } else {
1844 1.43 augustss if (bufno == sc->sc_nbufs - 1) {
1845 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].voccntl |= GUSMASK_LOOP_ENABLE;
1846 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].volcntl &= ~(GUSMASK_VOICE_ROLL);
1847 1.43 augustss } else {
1848 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].voccntl &= ~GUSMASK_LOOP_ENABLE;
1849 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].volcntl |= GUSMASK_VOICE_ROLL;
1850 1.43 augustss }
1851 1.1 brezak }
1852 1.1 brezak
1853 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, GUS_VOICE_LEFT);
1854 1.1 brezak
1855 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
1856 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[GUS_VOICE_LEFT].voccntl);
1857 1.1 brezak
1858 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
1859 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[GUS_VOICE_LEFT].volcntl);
1860 1.1 brezak
1861 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].current_addr =
1862 1.87 kent GUS_MEM_OFFSET + sc->sc_chanblocksize * bufno;
1863 1.43 augustss sc->sc_voc[GUS_VOICE_LEFT].end_addr =
1864 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].current_addr + sc->sc_chanblocksize - 1;
1865 1.43 augustss sc->sc_voc[GUS_VOICE_RIGHT].current_addr =
1866 1.87 kent sc->sc_voc[GUS_VOICE_LEFT].current_addr +
1867 1.87 kent (gus_dostereo && sc->sc_channels == 2 ? GUS_LEFT_RIGHT_OFFSET : 0);
1868 1.43 augustss /*
1869 1.43 augustss * set up right channel to just loop forever, no interrupts,
1870 1.43 augustss * starting at the buffer we just filled. We'll feed it data
1871 1.43 augustss * at the same time as left channel.
1872 1.43 augustss */
1873 1.43 augustss sc->sc_voc[GUS_VOICE_RIGHT].voccntl |= GUSMASK_LOOP_ENABLE;
1874 1.43 augustss sc->sc_voc[GUS_VOICE_RIGHT].volcntl &= ~(GUSMASK_VOICE_ROLL);
1875 1.1 brezak
1876 1.1 brezak #ifdef GUSPLAYDEBUG
1877 1.43 augustss if (gusstats) {
1878 1.43 augustss microtime(&playstats[playcntr].tv);
1879 1.43 augustss playstats[playcntr].curaddr = sc->sc_voc[GUS_VOICE_LEFT].current_addr;
1880 1.1 brezak
1881 1.43 augustss playstats[playcntr].voccntl = sc->sc_voc[GUS_VOICE_LEFT].voccntl;
1882 1.43 augustss playstats[playcntr].volcntl = sc->sc_voc[GUS_VOICE_LEFT].volcntl;
1883 1.43 augustss playstats[playcntr].endaddr = sc->sc_voc[GUS_VOICE_LEFT].end_addr;
1884 1.43 augustss playstats[playcntr].playbuf = bufno;
1885 1.43 augustss playstats[playcntr].dmabuf = sc->sc_dmabuf;
1886 1.43 augustss playstats[playcntr].bufcnt = sc->sc_bufcnt;
1887 1.43 augustss playstats[playcntr].vaction = 5;
1888 1.82 gson playcntr = (playcntr + 1) % NDMARECS;
1889 1.43 augustss }
1890 1.1 brezak #endif
1891 1.1 brezak
1892 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, GUS_VOICE_RIGHT);
1893 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
1894 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[GUS_VOICE_RIGHT].voccntl);
1895 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
1896 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[GUS_VOICE_RIGHT].volcntl);
1897 1.43 augustss
1898 1.43 augustss gus_start_voice(sc, GUS_VOICE_RIGHT, 0);
1899 1.43 augustss gus_start_voice(sc, GUS_VOICE_LEFT, 1);
1900 1.43 augustss if (sc->sc_playbuf == -1)
1901 1.43 augustss /* mark start of playing */
1902 1.43 augustss sc->sc_playbuf = bufno;
1903 1.1 brezak }
1904 1.1 brezak
1905 1.8 jtk STATIC int
1906 1.87 kent gus_continue_playing(struct gus_softc *sc, int voice)
1907 1.1 brezak {
1908 1.87 kent bus_space_tag_t iot;
1909 1.87 kent bus_space_handle_t ioh2;
1910 1.1 brezak
1911 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
1912 1.107 jmcneill
1913 1.43 augustss /*
1914 1.43 augustss * stop this voice from interrupting while we work.
1915 1.43 augustss */
1916 1.87 kent iot = sc->sc_iot;
1917 1.87 kent ioh2 = sc->sc_ioh2;
1918 1.1 brezak
1919 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
1920 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
1921 1.87 kent sc->sc_voc[voice].voccntl & ~(GUSMASK_VOICE_IRQ));
1922 1.1 brezak
1923 1.87 kent /*
1924 1.43 augustss * update playbuf to point to the buffer the hardware just started
1925 1.43 augustss * playing
1926 1.43 augustss */
1927 1.106 mrg sc->sc_playbuf = (sc->sc_playbuf + 1) % sc->sc_nbufs;
1928 1.87 kent
1929 1.43 augustss /*
1930 1.43 augustss * account for buffer just finished
1931 1.43 augustss */
1932 1.43 augustss if (--sc->sc_bufcnt == 0) {
1933 1.43 augustss DPRINTF(("gus: bufcnt 0 on continuing voice?\n"));
1934 1.43 augustss }
1935 1.43 augustss if (sc->sc_playbuf == sc->sc_dmabuf && (sc->sc_flags & GUS_LOCKED)) {
1936 1.109 chs aprint_error_dev(sc->sc_dev, "continue into active dmabuf?\n");
1937 1.43 augustss return 1;
1938 1.43 augustss }
1939 1.1 brezak
1940 1.43 augustss /*
1941 1.43 augustss * Select the end of the buffer based on the currently active
1942 1.43 augustss * buffer, [plus extra contiguous buffers (if ready)].
1943 1.43 augustss */
1944 1.1 brezak
1945 1.87 kent /*
1946 1.43 augustss * set endpoint at end of buffer we just started playing.
1947 1.43 augustss *
1948 1.43 augustss * The total gets -1 because end addrs are one less than you might
1949 1.43 augustss * think (the end_addr is the address of the last sample to play)
1950 1.43 augustss */
1951 1.43 augustss gus_set_endaddr(sc, voice, GUS_MEM_OFFSET +
1952 1.43 augustss sc->sc_chanblocksize * (sc->sc_playbuf + 1) - 1);
1953 1.1 brezak
1954 1.43 augustss if (sc->sc_bufcnt < 2) {
1955 1.43 augustss /*
1956 1.43 augustss * Clear out the loop and roll flags, and rotate the currently
1957 1.43 augustss * playing buffer. That way, if we don't manage to get more
1958 1.43 augustss * data before this buffer finishes, we'll just stop.
1959 1.43 augustss */
1960 1.43 augustss sc->sc_voc[voice].voccntl &= ~GUSMASK_LOOP_ENABLE;
1961 1.43 augustss sc->sc_voc[voice].volcntl &= ~GUSMASK_VOICE_ROLL;
1962 1.43 augustss playstats[playcntr].vaction = 0;
1963 1.1 brezak } else {
1964 1.43 augustss /*
1965 1.43 augustss * We have some buffers to play. set LOOP if we're on the
1966 1.43 augustss * last buffer in the ring, otherwise set ROLL.
1967 1.43 augustss */
1968 1.43 augustss if (sc->sc_playbuf == sc->sc_nbufs - 1) {
1969 1.43 augustss sc->sc_voc[voice].voccntl |= GUSMASK_LOOP_ENABLE;
1970 1.43 augustss sc->sc_voc[voice].volcntl &= ~GUSMASK_VOICE_ROLL;
1971 1.43 augustss playstats[playcntr].vaction = 1;
1972 1.43 augustss } else {
1973 1.43 augustss sc->sc_voc[voice].voccntl &= ~GUSMASK_LOOP_ENABLE;
1974 1.43 augustss sc->sc_voc[voice].volcntl |= GUSMASK_VOICE_ROLL;
1975 1.43 augustss playstats[playcntr].vaction = 2;
1976 1.43 augustss }
1977 1.1 brezak }
1978 1.1 brezak #ifdef GUSPLAYDEBUG
1979 1.43 augustss if (gusstats) {
1980 1.43 augustss microtime(&playstats[playcntr].tv);
1981 1.43 augustss playstats[playcntr].curaddr = gus_get_curaddr(sc, voice);
1982 1.1 brezak
1983 1.43 augustss playstats[playcntr].voccntl = sc->sc_voc[voice].voccntl;
1984 1.43 augustss playstats[playcntr].volcntl = sc->sc_voc[voice].volcntl;
1985 1.43 augustss playstats[playcntr].endaddr = sc->sc_voc[voice].end_addr;
1986 1.43 augustss playstats[playcntr].playbuf = sc->sc_playbuf;
1987 1.43 augustss playstats[playcntr].dmabuf = sc->sc_dmabuf;
1988 1.43 augustss playstats[playcntr].bufcnt = sc->sc_bufcnt;
1989 1.82 gson playcntr = (playcntr + 1) % NDMARECS;
1990 1.43 augustss }
1991 1.1 brezak #endif
1992 1.1 brezak
1993 1.43 augustss /*
1994 1.43 augustss * (re-)set voice parameters. This will reenable interrupts from this
1995 1.43 augustss * voice.
1996 1.43 augustss */
1997 1.1 brezak
1998 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
1999 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].voccntl);
2000 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
2001 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].volcntl);
2002 1.43 augustss return 0;
2003 1.1 brezak }
2004 1.1 brezak
2005 1.1 brezak /*
2006 1.107 jmcneill * Send/receive data into GUS's DRAM using DMA.
2007 1.1 brezak */
2008 1.8 jtk STATIC void
2009 1.87 kent gusdmaout(struct gus_softc *sc, int flags,
2010 1.97 christos u_long gusaddr, void *buffaddr, int length)
2011 1.1 brezak {
2012 1.87 kent unsigned char c;
2013 1.87 kent bus_space_tag_t iot;
2014 1.87 kent bus_space_handle_t ioh2;
2015 1.1 brezak
2016 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2017 1.107 jmcneill
2018 1.1 brezak DMAPRINTF(("gusdmaout flags=%x scflags=%x\n", flags, sc->sc_flags));
2019 1.87 kent c = (unsigned char) flags;
2020 1.87 kent iot = sc->sc_iot;
2021 1.87 kent ioh2 = sc->sc_ioh2;
2022 1.1 brezak
2023 1.1 brezak sc->sc_gusaddr = gusaddr;
2024 1.1 brezak
2025 1.1 brezak /*
2026 1.1 brezak * If we're using a 16 bit DMA channel, we have to jump through some
2027 1.1 brezak * extra hoops; this includes translating the DRAM address a bit
2028 1.1 brezak */
2029 1.1 brezak
2030 1.66 mycroft if (sc->sc_playdrq >= 4) {
2031 1.1 brezak c |= GUSMASK_DMA_WIDTH;
2032 1.1 brezak gusaddr = convert_to_16bit(gusaddr);
2033 1.1 brezak }
2034 1.1 brezak
2035 1.1 brezak /*
2036 1.1 brezak * Add flag bits that we always set - fast DMA, enable IRQ
2037 1.1 brezak */
2038 1.1 brezak
2039 1.1 brezak c |= GUSMASK_DMA_ENABLE | GUSMASK_DMA_R0 | GUSMASK_DMA_IRQ;
2040 1.1 brezak
2041 1.1 brezak /*
2042 1.1 brezak * Make sure the GUS _isn't_ setup for DMA
2043 1.1 brezak */
2044 1.1 brezak
2045 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
2046 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0);
2047 1.1 brezak
2048 1.1 brezak /*
2049 1.1 brezak * Tell the PC DMA controller to start doing DMA
2050 1.1 brezak */
2051 1.1 brezak
2052 1.1 brezak sc->sc_dmaoutaddr = (u_char *) buffaddr;
2053 1.1 brezak sc->sc_dmaoutcnt = length;
2054 1.87 kent isa_dmastart(sc->sc_ic, sc->sc_playdrq, buffaddr, length,
2055 1.87 kent NULL, DMAMODE_WRITE, BUS_DMA_NOWAIT);
2056 1.1 brezak
2057 1.1 brezak /*
2058 1.1 brezak * Set up DMA address - use the upper 16 bits ONLY
2059 1.1 brezak */
2060 1.1 brezak
2061 1.1 brezak sc->sc_flags |= GUS_DMAOUT_ACTIVE;
2062 1.1 brezak
2063 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_START);
2064 1.87 kent bus_space_write_2(iot, ioh2, GUS_DATA_LOW, (int) (gusaddr >> 4));
2065 1.1 brezak
2066 1.87 kent /*
2067 1.87 kent * Tell the GUS to start doing DMA
2068 1.87 kent */
2069 1.1 brezak
2070 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
2071 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, c);
2072 1.1 brezak
2073 1.1 brezak /*
2074 1.1 brezak * XXX If we don't finish in one second, give up...
2075 1.1 brezak */
2076 1.69 thorpej callout_reset(&sc->sc_dmaout_ch, hz, gus_dmaout_timeout, sc);
2077 1.1 brezak }
2078 1.1 brezak
2079 1.1 brezak /*
2080 1.107 jmcneill * Start a voice playing on the GUS.
2081 1.1 brezak */
2082 1.1 brezak
2083 1.8 jtk STATIC void
2084 1.87 kent gus_start_voice(struct gus_softc *sc, int voice, int intrs)
2085 1.1 brezak {
2086 1.87 kent bus_space_tag_t iot;
2087 1.87 kent bus_space_handle_t ioh2;
2088 1.14 christos u_long start;
2089 1.14 christos u_long current;
2090 1.14 christos u_long end;
2091 1.1 brezak
2092 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2093 1.107 jmcneill
2094 1.87 kent iot = sc->sc_iot;
2095 1.87 kent ioh2 = sc->sc_ioh2;
2096 1.1 brezak /*
2097 1.1 brezak * Pick all the values for the voice out of the gus_voice struct
2098 1.1 brezak * and use those to program the voice
2099 1.1 brezak */
2100 1.1 brezak
2101 1.87 kent start = sc->sc_voc[voice].start_addr;
2102 1.87 kent current = sc->sc_voc[voice].current_addr;
2103 1.87 kent end = sc->sc_voc[voice].end_addr;
2104 1.1 brezak
2105 1.87 kent /*
2106 1.1 brezak * If we're using 16 bit data, mangle the addresses a bit
2107 1.1 brezak */
2108 1.1 brezak
2109 1.1 brezak if (sc->sc_voc[voice].voccntl & GUSMASK_DATA_SIZE16) {
2110 1.87 kent /* -1 on start so that we get onto sample boundary--other
2111 1.87 kent * code always sets it for 1-byte rollover protection */
2112 1.1 brezak start = convert_to_16bit(start-1);
2113 1.1 brezak current = convert_to_16bit(current);
2114 1.1 brezak end = convert_to_16bit(end);
2115 1.1 brezak }
2116 1.1 brezak
2117 1.1 brezak /*
2118 1.1 brezak * Select the voice we want to use, and program the data addresses
2119 1.1 brezak */
2120 1.1 brezak
2121 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2122 1.1 brezak
2123 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_ADDR_HIGH);
2124 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_HIGH(start));
2125 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_ADDR_LOW);
2126 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_LOW(start));
2127 1.43 augustss
2128 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_HIGH);
2129 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_HIGH(current));
2130 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_LOW);
2131 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_LOW(current));
2132 1.43 augustss
2133 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_HIGH);
2134 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_HIGH(end));
2135 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_LOW);
2136 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_LOW(end));
2137 1.1 brezak
2138 1.1 brezak /*
2139 1.1 brezak * (maybe) enable interrupts, disable voice stopping
2140 1.1 brezak */
2141 1.1 brezak
2142 1.1 brezak if (intrs) {
2143 1.1 brezak sc->sc_flags |= GUS_PLAYING; /* playing is about to start */
2144 1.1 brezak sc->sc_voc[voice].voccntl |= GUSMASK_VOICE_IRQ;
2145 1.1 brezak DMAPRINTF(("gus voice playing=%x\n", sc->sc_flags));
2146 1.1 brezak } else
2147 1.1 brezak sc->sc_voc[voice].voccntl &= ~GUSMASK_VOICE_IRQ;
2148 1.1 brezak sc->sc_voc[voice].voccntl &= ~(GUSMASK_VOICE_STOPPED |
2149 1.87 kent GUSMASK_STOP_VOICE);
2150 1.1 brezak
2151 1.1 brezak /*
2152 1.1 brezak * Tell the GUS about it. Note that we're doing volume ramping here
2153 1.1 brezak * from 0 up to the set volume to help reduce clicks.
2154 1.1 brezak */
2155 1.1 brezak
2156 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_VOLUME);
2157 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2158 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_VOLUME);
2159 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2160 1.87 kent sc->sc_voc[voice].current_volume >> 4);
2161 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_VOLUME);
2162 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x00);
2163 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_RATE);
2164 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 63);
2165 1.43 augustss
2166 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
2167 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].voccntl);
2168 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
2169 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2170 1.1 brezak delay(50);
2171 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
2172 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].voccntl);
2173 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
2174 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2175 1.1 brezak
2176 1.1 brezak }
2177 1.1 brezak
2178 1.1 brezak /*
2179 1.107 jmcneill * Stop a given voice.
2180 1.1 brezak */
2181 1.8 jtk STATIC void
2182 1.87 kent gus_stop_voice(struct gus_softc *sc, int voice, int intrs_too)
2183 1.1 brezak {
2184 1.87 kent bus_space_tag_t iot;
2185 1.87 kent bus_space_handle_t ioh2;
2186 1.1 brezak
2187 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2188 1.107 jmcneill
2189 1.87 kent iot = sc->sc_iot;
2190 1.87 kent ioh2 = sc->sc_ioh2;
2191 1.1 brezak sc->sc_voc[voice].voccntl |= GUSMASK_VOICE_STOPPED |
2192 1.87 kent GUSMASK_STOP_VOICE;
2193 1.1 brezak if (intrs_too) {
2194 1.87 kent sc->sc_voc[voice].voccntl &= ~(GUSMASK_VOICE_IRQ);
2195 1.87 kent /* no more DMA to do */
2196 1.87 kent sc->sc_flags &= ~GUS_PLAYING;
2197 1.1 brezak }
2198 1.1 brezak DMAPRINTF(("gusintr voice notplaying=%x\n", sc->sc_flags));
2199 1.1 brezak
2200 1.43 augustss guspoke(iot, ioh2, 0L, 0);
2201 1.1 brezak
2202 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2203 1.1 brezak
2204 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_VOLUME);
2205 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2206 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
2207 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].voccntl);
2208 1.1 brezak delay(100);
2209 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_VOLUME);
2210 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2211 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
2212 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[voice].voccntl);
2213 1.43 augustss
2214 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_HIGH);
2215 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2216 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_LOW);
2217 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2218 1.1 brezak
2219 1.1 brezak }
2220 1.1 brezak
2221 1.1 brezak
2222 1.1 brezak /*
2223 1.107 jmcneill * Set the volume of a given voice.
2224 1.1 brezak */
2225 1.8 jtk STATIC void
2226 1.87 kent gus_set_volume(struct gus_softc *sc, int voice, int volume)
2227 1.1 brezak {
2228 1.87 kent bus_space_tag_t iot;
2229 1.87 kent bus_space_handle_t ioh2;
2230 1.1 brezak unsigned int gusvol;
2231 1.1 brezak
2232 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2233 1.107 jmcneill
2234 1.87 kent iot = sc->sc_iot;
2235 1.87 kent ioh2 = sc->sc_ioh2;
2236 1.1 brezak gusvol = gus_log_volumes[volume < 512 ? volume : 511];
2237 1.1 brezak
2238 1.1 brezak sc->sc_voc[voice].current_volume = gusvol;
2239 1.1 brezak
2240 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2241 1.1 brezak
2242 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_VOLUME);
2243 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2244 1.110 msaitoh (unsigned char)(gusvol >> 4));
2245 1.1 brezak
2246 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_VOLUME);
2247 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2248 1.110 msaitoh (unsigned char)(gusvol >> 4));
2249 1.1 brezak
2250 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_VOLUME);
2251 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, gusvol << 4);
2252 1.1 brezak delay(500);
2253 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, gusvol << 4);
2254 1.1 brezak
2255 1.1 brezak }
2256 1.1 brezak
2257 1.1 brezak /*
2258 1.23 augustss * Interface to the audio layer.
2259 1.1 brezak */
2260 1.1 brezak
2261 1.1 brezak int
2262 1.87 kent gusmax_set_params(void *addr, int setmode, int usemode, audio_params_t *p,
2263 1.87 kent audio_params_t *r, stream_filter_list_t *pfil,
2264 1.87 kent stream_filter_list_t *rfil)
2265 1.23 augustss {
2266 1.87 kent struct ad1848_isa_softc *ac;
2267 1.87 kent struct gus_softc *sc;
2268 1.23 augustss int error;
2269 1.23 augustss
2270 1.87 kent ac = addr;
2271 1.87 kent sc = ac->sc_ad1848.parent;
2272 1.86 kent error = ad1848_set_params(ac, setmode, usemode, p, r, pfil, rfil);
2273 1.23 augustss if (error)
2274 1.23 augustss return error;
2275 1.86 kent /*
2276 1.86 kent * ad1848_set_params() sets a filter for
2277 1.86 kent * SLINEAR_LE 8, SLINEAR_BE 16, ULINEAR_LE 16, ULINEAR_BE 16.
2278 1.86 kent * gus_set_params() sets a filter for
2279 1.86 kent * ULAW, ALAW, ULINEAR_BE (16), SLINEAR_BE (16)
2280 1.86 kent */
2281 1.86 kent error = gus_set_params(sc, setmode, usemode, p, r, pfil, rfil);
2282 1.25 augustss return error;
2283 1.23 augustss }
2284 1.23 augustss
2285 1.23 augustss int
2286 1.107 jmcneill gus_set_params(void *addr,int setmode, int usemode, audio_params_t *p,
2287 1.107 jmcneill audio_params_t *r, stream_filter_list_t *pfil,
2288 1.107 jmcneill stream_filter_list_t *rfil)
2289 1.23 augustss {
2290 1.86 kent audio_params_t hw;
2291 1.87 kent struct gus_softc *sc;
2292 1.1 brezak
2293 1.87 kent sc = addr;
2294 1.23 augustss switch (p->encoding) {
2295 1.21 mycroft case AUDIO_ENCODING_ULAW:
2296 1.39 augustss case AUDIO_ENCODING_ALAW:
2297 1.32 augustss case AUDIO_ENCODING_SLINEAR_LE:
2298 1.24 augustss case AUDIO_ENCODING_ULINEAR_LE:
2299 1.32 augustss case AUDIO_ENCODING_SLINEAR_BE:
2300 1.29 jtk case AUDIO_ENCODING_ULINEAR_BE:
2301 1.21 mycroft break;
2302 1.21 mycroft default:
2303 1.87 kent return EINVAL;
2304 1.21 mycroft }
2305 1.1 brezak
2306 1.112 nat mutex_spin_enter(&sc->sc_codec.sc_ad1848.sc_intr_lock);
2307 1.1 brezak
2308 1.23 augustss if (p->precision == 8) {
2309 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].voccntl &= ~GUSMASK_DATA_SIZE16;
2310 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].voccntl &= ~GUSMASK_DATA_SIZE16;
2311 1.1 brezak } else {
2312 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].voccntl |= GUSMASK_DATA_SIZE16;
2313 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].voccntl |= GUSMASK_DATA_SIZE16;
2314 1.1 brezak }
2315 1.21 mycroft
2316 1.23 augustss sc->sc_encoding = p->encoding;
2317 1.23 augustss sc->sc_precision = p->precision;
2318 1.27 jtk sc->sc_channels = p->channels;
2319 1.21 mycroft
2320 1.28 augustss if (p->sample_rate > gus_max_frequency[sc->sc_voices - GUS_MIN_VOICES])
2321 1.28 augustss p->sample_rate = gus_max_frequency[sc->sc_voices - GUS_MIN_VOICES];
2322 1.41 augustss if (setmode & AUMODE_RECORD)
2323 1.28 augustss sc->sc_irate = p->sample_rate;
2324 1.41 augustss if (setmode & AUMODE_PLAY)
2325 1.28 augustss sc->sc_orate = p->sample_rate;
2326 1.28 augustss
2327 1.112 nat mutex_spin_exit(&sc->sc_codec.sc_ad1848.sc_intr_lock);
2328 1.107 jmcneill
2329 1.86 kent hw = *p;
2330 1.86 kent /* clear req_size before setting a filter to avoid confliction
2331 1.86 kent * in gusmax_set_params() */
2332 1.29 jtk switch (p->encoding) {
2333 1.29 jtk case AUDIO_ENCODING_ULAW:
2334 1.86 kent hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
2335 1.86 kent pfil->req_size = rfil->req_size = 0;
2336 1.86 kent pfil->append(pfil, mulaw_to_linear8, &hw);
2337 1.86 kent rfil->append(rfil, linear8_to_mulaw, &hw);
2338 1.29 jtk break;
2339 1.39 augustss case AUDIO_ENCODING_ALAW:
2340 1.86 kent hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
2341 1.86 kent pfil->req_size = rfil->req_size = 0;
2342 1.86 kent pfil->append(pfil, alaw_to_linear8, &hw);
2343 1.86 kent rfil->append(rfil, linear8_to_alaw, &hw);
2344 1.39 augustss break;
2345 1.29 jtk case AUDIO_ENCODING_ULINEAR_BE:
2346 1.86 kent hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
2347 1.86 kent pfil->req_size = rfil->req_size = 0;
2348 1.86 kent pfil->append(pfil, swap_bytes, &hw);
2349 1.86 kent rfil->append(rfil, swap_bytes, &hw);
2350 1.86 kent break;
2351 1.32 augustss case AUDIO_ENCODING_SLINEAR_BE:
2352 1.86 kent hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
2353 1.86 kent pfil->req_size = rfil->req_size = 0;
2354 1.86 kent pfil->append(pfil, swap_bytes, &hw);
2355 1.86 kent rfil->append(rfil, swap_bytes, &hw);
2356 1.29 jtk break;
2357 1.29 jtk }
2358 1.28 augustss
2359 1.1 brezak return 0;
2360 1.1 brezak }
2361 1.28 augustss
2362 1.1 brezak /*
2363 1.1 brezak * Interface to the audio layer - set the blocksize to the correct number
2364 1.1 brezak * of units
2365 1.1 brezak */
2366 1.1 brezak
2367 1.1 brezak int
2368 1.97 christos gusmax_round_blocksize(void *addr, int blocksize,
2369 1.87 kent int mode, const audio_params_t *param)
2370 1.1 brezak {
2371 1.87 kent struct ad1848_isa_softc *ac;
2372 1.87 kent struct gus_softc *sc;
2373 1.1 brezak
2374 1.87 kent ac = addr;
2375 1.87 kent sc = ac->sc_ad1848.parent;
2376 1.86 kent /* blocksize = ad1848_round_blocksize(ac, blocksize, mode, param);*/
2377 1.86 kent return gus_round_blocksize(sc, blocksize, mode, param);
2378 1.1 brezak }
2379 1.1 brezak
2380 1.1 brezak int
2381 1.97 christos gus_round_blocksize(void *addr, int blocksize,
2382 1.96 christos int mode, const audio_params_t *param)
2383 1.1 brezak {
2384 1.87 kent struct gus_softc *sc;
2385 1.1 brezak
2386 1.1 brezak DPRINTF(("gus_round_blocksize called\n"));
2387 1.87 kent sc = addr;
2388 1.1 brezak
2389 1.39 augustss if ((sc->sc_encoding == AUDIO_ENCODING_ULAW ||
2390 1.39 augustss sc->sc_encoding == AUDIO_ENCODING_ALAW) && blocksize > 32768)
2391 1.1 brezak blocksize = 32768;
2392 1.1 brezak else if (blocksize > 65536)
2393 1.1 brezak blocksize = 65536;
2394 1.1 brezak
2395 1.1 brezak if ((blocksize % GUS_BUFFER_MULTIPLE) != 0)
2396 1.1 brezak blocksize = (blocksize / GUS_BUFFER_MULTIPLE + 1) *
2397 1.1 brezak GUS_BUFFER_MULTIPLE;
2398 1.1 brezak
2399 1.1 brezak sc->sc_blocksize = blocksize;
2400 1.1 brezak /* multi-buffering not quite working yet. */
2401 1.1 brezak sc->sc_nbufs = /*GUS_MEM_FOR_BUFFERS / blocksize*/ 2;
2402 1.1 brezak
2403 1.1 brezak gus_set_chan_addrs(sc);
2404 1.1 brezak
2405 1.1 brezak return blocksize;
2406 1.1 brezak }
2407 1.1 brezak
2408 1.1 brezak int
2409 1.97 christos gus_get_out_gain(void *addr)
2410 1.1 brezak {
2411 1.87 kent struct gus_softc *sc;
2412 1.1 brezak
2413 1.1 brezak DPRINTF(("gus_get_out_gain called\n"));
2414 1.87 kent sc = (struct gus_softc *) addr;
2415 1.1 brezak return sc->sc_ogain / 2;
2416 1.1 brezak }
2417 1.1 brezak
2418 1.87 kent STATIC inline void
2419 1.87 kent gus_set_voices(struct gus_softc *sc, int voices)
2420 1.1 brezak {
2421 1.87 kent bus_space_tag_t iot;
2422 1.87 kent bus_space_handle_t ioh2;
2423 1.87 kent
2424 1.87 kent iot = sc->sc_iot;
2425 1.87 kent ioh2 = sc->sc_ioh2;
2426 1.1 brezak /*
2427 1.1 brezak * Select the active number of voices
2428 1.1 brezak */
2429 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_ACTIVE_VOICES);
2430 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, (voices-1) | 0xc0);
2431 1.1 brezak
2432 1.1 brezak sc->sc_voices = voices;
2433 1.1 brezak }
2434 1.1 brezak
2435 1.1 brezak /*
2436 1.1 brezak * Actually set the settings of various values on the card
2437 1.1 brezak */
2438 1.1 brezak int
2439 1.97 christos gusmax_commit_settings(void *addr)
2440 1.1 brezak {
2441 1.87 kent struct ad1848_isa_softc *ac;
2442 1.87 kent struct gus_softc *sc;
2443 1.41 augustss int error;
2444 1.1 brezak
2445 1.87 kent ac = addr;
2446 1.87 kent sc = ac->sc_ad1848.parent;
2447 1.41 augustss error = ad1848_commit_settings(ac);
2448 1.41 augustss if (error)
2449 1.41 augustss return error;
2450 1.1 brezak return gus_commit_settings(sc);
2451 1.1 brezak }
2452 1.1 brezak
2453 1.1 brezak /*
2454 1.107 jmcneill * Commit the settings.
2455 1.1 brezak */
2456 1.1 brezak int
2457 1.87 kent gus_commit_settings(void *addr)
2458 1.1 brezak {
2459 1.87 kent struct gus_softc *sc;
2460 1.1 brezak
2461 1.87 kent sc = addr;
2462 1.1 brezak DPRINTF(("gus_commit_settings called (gain = %d)\n",sc->sc_ogain));
2463 1.1 brezak
2464 1.107 jmcneill mutex_spin_enter(&sc->sc_codec.sc_ad1848.sc_intr_lock);
2465 1.1 brezak gus_set_recrate(sc, sc->sc_irate);
2466 1.1 brezak gus_set_volume(sc, GUS_VOICE_LEFT, sc->sc_ogain);
2467 1.1 brezak gus_set_volume(sc, GUS_VOICE_RIGHT, sc->sc_ogain);
2468 1.1 brezak gus_set_samprate(sc, GUS_VOICE_LEFT, sc->sc_orate);
2469 1.1 brezak gus_set_samprate(sc, GUS_VOICE_RIGHT, sc->sc_orate);
2470 1.107 jmcneill mutex_spin_exit(&sc->sc_codec.sc_ad1848.sc_intr_lock);
2471 1.107 jmcneill
2472 1.1 brezak gus_set_chan_addrs(sc);
2473 1.1 brezak
2474 1.1 brezak return 0;
2475 1.1 brezak }
2476 1.1 brezak
2477 1.8 jtk STATIC void
2478 1.87 kent gus_set_chan_addrs(struct gus_softc *sc)
2479 1.1 brezak {
2480 1.87 kent
2481 1.1 brezak /*
2482 1.1 brezak * We use sc_nbufs * blocksize bytes of storage in the on-board GUS
2483 1.88 perry * ram.
2484 1.1 brezak * For mono, each of the sc_nbufs buffers is DMA'd to in one chunk,
2485 1.1 brezak * and both left & right channels play the same buffer.
2486 1.1 brezak *
2487 1.1 brezak * For stereo, each channel gets a contiguous half of the memory,
2488 1.1 brezak * and each has sc_nbufs buffers of size blocksize/2.
2489 1.1 brezak * Stereo data are deinterleaved in main memory before the DMA out
2490 1.1 brezak * routines are called to queue the output.
2491 1.1 brezak *
2492 1.1 brezak * The blocksize per channel is kept in sc_chanblocksize.
2493 1.1 brezak */
2494 1.1 brezak if (sc->sc_channels == 2)
2495 1.1 brezak sc->sc_chanblocksize = sc->sc_blocksize/2;
2496 1.1 brezak else
2497 1.1 brezak sc->sc_chanblocksize = sc->sc_blocksize;
2498 1.1 brezak
2499 1.1 brezak sc->sc_voc[GUS_VOICE_LEFT].start_addr = GUS_MEM_OFFSET - 1;
2500 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].start_addr =
2501 1.1 brezak (gus_dostereo && sc->sc_channels == 2 ? GUS_LEFT_RIGHT_OFFSET : 0)
2502 1.1 brezak + GUS_MEM_OFFSET - 1;
2503 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].current_addr =
2504 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].start_addr + 1;
2505 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].end_addr =
2506 1.1 brezak sc->sc_voc[GUS_VOICE_RIGHT].start_addr +
2507 1.1 brezak sc->sc_nbufs * sc->sc_chanblocksize;
2508 1.1 brezak
2509 1.1 brezak }
2510 1.1 brezak
2511 1.1 brezak /*
2512 1.107 jmcneill * Set the sample rate of the given voice.
2513 1.1 brezak */
2514 1.8 jtk STATIC void
2515 1.87 kent gus_set_samprate(struct gus_softc *sc, int voice, int freq)
2516 1.1 brezak {
2517 1.87 kent bus_space_tag_t iot;
2518 1.87 kent bus_space_handle_t ioh2;
2519 1.1 brezak unsigned int fc;
2520 1.87 kent u_long temp, f;
2521 1.1 brezak
2522 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2523 1.107 jmcneill
2524 1.87 kent iot = sc->sc_iot;
2525 1.87 kent ioh2 = sc->sc_ioh2;
2526 1.87 kent f = (u_long) freq;
2527 1.1 brezak /*
2528 1.1 brezak * calculate fc based on the number of active voices;
2529 1.1 brezak * we need to use longs to preserve enough bits
2530 1.1 brezak */
2531 1.1 brezak
2532 1.14 christos temp = (u_long) gus_max_frequency[sc->sc_voices-GUS_MIN_VOICES];
2533 1.1 brezak
2534 1.87 kent fc = (unsigned int)(((f << 9L) + (temp >> 1L)) / temp);
2535 1.87 kent fc <<= 1;
2536 1.1 brezak
2537 1.1 brezak /*
2538 1.1 brezak * Program the voice frequency, and set it in the voice data record
2539 1.1 brezak */
2540 1.1 brezak
2541 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2542 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_FREQ_CONTROL);
2543 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, fc);
2544 1.1 brezak
2545 1.1 brezak sc->sc_voc[voice].rate = freq;
2546 1.1 brezak
2547 1.1 brezak }
2548 1.1 brezak
2549 1.1 brezak /*
2550 1.1 brezak * Set the sample rate of the recording frequency. Formula is from the GUS
2551 1.107 jmcneill * SDK.
2552 1.1 brezak */
2553 1.8 jtk STATIC void
2554 1.87 kent gus_set_recrate(struct gus_softc *sc, u_long rate)
2555 1.1 brezak {
2556 1.87 kent bus_space_tag_t iot;
2557 1.87 kent bus_space_handle_t ioh2;
2558 1.1 brezak u_char realrate;
2559 1.87 kent
2560 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2561 1.107 jmcneill
2562 1.1 brezak DPRINTF(("gus_set_recrate %lu\n", rate));
2563 1.87 kent iot = sc->sc_iot;
2564 1.87 kent ioh2 = sc->sc_ioh2;
2565 1.1 brezak
2566 1.14 christos #if 0
2567 1.14 christos realrate = 9878400/(16*(rate+2)); /* formula from GUS docs */
2568 1.14 christos #endif
2569 1.1 brezak realrate = (9878400 >> 4)/rate - 2; /* formula from code, sigh. */
2570 1.1 brezak
2571 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_FREQ);
2572 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, realrate);
2573 1.1 brezak }
2574 1.1 brezak
2575 1.1 brezak /*
2576 1.1 brezak * Interface to the audio layer - turn the output on or off. Note that some
2577 1.1 brezak * of these bits are flipped in the register
2578 1.1 brezak */
2579 1.1 brezak
2580 1.1 brezak int
2581 1.87 kent gusmax_speaker_ctl(void *addr, int newstate)
2582 1.1 brezak {
2583 1.87 kent struct ad1848_isa_softc *sc;
2584 1.87 kent
2585 1.87 kent sc = addr;
2586 1.62 jtk return gus_speaker_ctl(sc->sc_ad1848.parent, newstate);
2587 1.1 brezak }
2588 1.1 brezak
2589 1.1 brezak int
2590 1.87 kent gus_speaker_ctl(void *addr, int newstate)
2591 1.87 kent {
2592 1.87 kent struct gus_softc *sc;
2593 1.87 kent bus_space_tag_t iot;
2594 1.87 kent bus_space_handle_t ioh1;
2595 1.1 brezak
2596 1.87 kent sc = (struct gus_softc *) addr;
2597 1.87 kent iot = sc->sc_iot;
2598 1.87 kent ioh1 = sc->sc_ioh1;
2599 1.1 brezak /* Line out bit is flipped: 0 enables, 1 disables */
2600 1.1 brezak if ((newstate == SPKR_ON) &&
2601 1.1 brezak (sc->sc_mixcontrol & GUSMASK_LINE_OUT)) {
2602 1.1 brezak sc->sc_mixcontrol &= ~GUSMASK_LINE_OUT;
2603 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2604 1.1 brezak }
2605 1.1 brezak if ((newstate == SPKR_OFF) &&
2606 1.1 brezak (sc->sc_mixcontrol & GUSMASK_LINE_OUT) == 0) {
2607 1.1 brezak sc->sc_mixcontrol |= GUSMASK_LINE_OUT;
2608 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2609 1.1 brezak }
2610 1.1 brezak
2611 1.1 brezak return 0;
2612 1.1 brezak }
2613 1.1 brezak
2614 1.8 jtk STATIC int
2615 1.87 kent gus_linein_ctl(void *addr, int newstate)
2616 1.87 kent {
2617 1.87 kent struct gus_softc *sc;
2618 1.87 kent bus_space_tag_t iot;
2619 1.87 kent bus_space_handle_t ioh1;
2620 1.1 brezak
2621 1.87 kent sc = (struct gus_softc *) addr;
2622 1.87 kent iot = sc->sc_iot;
2623 1.87 kent ioh1 = sc->sc_ioh1;
2624 1.1 brezak /* Line in bit is flipped: 0 enables, 1 disables */
2625 1.1 brezak if ((newstate == SPKR_ON) &&
2626 1.1 brezak (sc->sc_mixcontrol & GUSMASK_LINE_IN)) {
2627 1.1 brezak sc->sc_mixcontrol &= ~GUSMASK_LINE_IN;
2628 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2629 1.1 brezak }
2630 1.1 brezak if ((newstate == SPKR_OFF) &&
2631 1.1 brezak (sc->sc_mixcontrol & GUSMASK_LINE_IN) == 0) {
2632 1.1 brezak sc->sc_mixcontrol |= GUSMASK_LINE_IN;
2633 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2634 1.1 brezak }
2635 1.1 brezak
2636 1.1 brezak return 0;
2637 1.1 brezak }
2638 1.1 brezak
2639 1.8 jtk STATIC int
2640 1.87 kent gus_mic_ctl(void *addr, int newstate)
2641 1.87 kent {
2642 1.87 kent struct gus_softc *sc;
2643 1.87 kent bus_space_tag_t iot;
2644 1.87 kent bus_space_handle_t ioh1;
2645 1.1 brezak
2646 1.87 kent sc = (struct gus_softc *) addr;
2647 1.87 kent iot = sc->sc_iot;
2648 1.87 kent ioh1 = sc->sc_ioh1;
2649 1.1 brezak /* Mic bit is normal: 1 enables, 0 disables */
2650 1.1 brezak if ((newstate == SPKR_ON) &&
2651 1.1 brezak (sc->sc_mixcontrol & GUSMASK_MIC_IN) == 0) {
2652 1.1 brezak sc->sc_mixcontrol |= GUSMASK_MIC_IN;
2653 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2654 1.1 brezak }
2655 1.1 brezak if ((newstate == SPKR_OFF) &&
2656 1.1 brezak (sc->sc_mixcontrol & GUSMASK_MIC_IN)) {
2657 1.1 brezak sc->sc_mixcontrol &= ~GUSMASK_MIC_IN;
2658 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL, sc->sc_mixcontrol);
2659 1.1 brezak }
2660 1.1 brezak
2661 1.1 brezak return 0;
2662 1.1 brezak }
2663 1.1 brezak
2664 1.1 brezak /*
2665 1.107 jmcneill * Set the end address of a give voice.
2666 1.1 brezak */
2667 1.8 jtk STATIC void
2668 1.87 kent gus_set_endaddr(struct gus_softc *sc, int voice, u_long addr)
2669 1.1 brezak {
2670 1.87 kent bus_space_tag_t iot;
2671 1.87 kent bus_space_handle_t ioh2;
2672 1.1 brezak
2673 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2674 1.107 jmcneill
2675 1.87 kent iot = sc->sc_iot;
2676 1.87 kent ioh2 = sc->sc_ioh2;
2677 1.1 brezak sc->sc_voc[voice].end_addr = addr;
2678 1.1 brezak
2679 1.1 brezak if (sc->sc_voc[voice].voccntl & GUSMASK_DATA_SIZE16)
2680 1.1 brezak addr = convert_to_16bit(addr);
2681 1.1 brezak
2682 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_HIGH);
2683 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_HIGH(addr));
2684 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_LOW);
2685 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_LOW(addr));
2686 1.1 brezak
2687 1.1 brezak }
2688 1.1 brezak
2689 1.15 jtk #ifdef GUSPLAYDEBUG
2690 1.1 brezak /*
2691 1.107 jmcneill * Set current address.
2692 1.1 brezak */
2693 1.8 jtk STATIC void
2694 1.87 kent gus_set_curaddr(struct gus_softc *sc, int voice, u_long addr)
2695 1.1 brezak {
2696 1.87 kent bus_space_tag_t iot;
2697 1.87 kent bus_space_handle_t ioh2;
2698 1.1 brezak
2699 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2700 1.107 jmcneill
2701 1.87 kent iot = sc->sc_iot;
2702 1.87 kent ioh2 = sc->sc_ioh2;
2703 1.1 brezak sc->sc_voc[voice].current_addr = addr;
2704 1.1 brezak
2705 1.1 brezak if (sc->sc_voc[voice].voccntl & GUSMASK_DATA_SIZE16)
2706 1.1 brezak addr = convert_to_16bit(addr);
2707 1.1 brezak
2708 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2709 1.1 brezak
2710 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_HIGH);
2711 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_HIGH(addr));
2712 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_LOW);
2713 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, ADDR_LOW(addr));
2714 1.1 brezak
2715 1.1 brezak }
2716 1.1 brezak
2717 1.1 brezak /*
2718 1.107 jmcneill * Get current GUS playback address.
2719 1.1 brezak */
2720 1.14 christos STATIC u_long
2721 1.87 kent gus_get_curaddr(struct gus_softc *sc, int voice)
2722 1.1 brezak {
2723 1.87 kent bus_space_tag_t iot;
2724 1.87 kent bus_space_handle_t ioh2;
2725 1.14 christos u_long addr;
2726 1.1 brezak
2727 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2728 1.107 jmcneill
2729 1.87 kent iot = sc->sc_iot;
2730 1.87 kent ioh2 = sc->sc_ioh2;
2731 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) voice);
2732 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_HIGH|GUSREG_READ);
2733 1.43 augustss addr = (bus_space_read_2(iot, ioh2, GUS_DATA_LOW) & 0x1fff) << 7;
2734 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_LOW|GUSREG_READ);
2735 1.43 augustss addr |= (bus_space_read_2(iot, ioh2, GUS_DATA_LOW) >> 9L) & 0x7f;
2736 1.1 brezak
2737 1.1 brezak if (sc->sc_voc[voice].voccntl & GUSMASK_DATA_SIZE16)
2738 1.1 brezak addr = (addr & 0xc0000) | ((addr & 0x1ffff) << 1); /* undo 16-bit change */
2739 1.33 augustss DPRINTF(("gus voice %d curaddr %ld end_addr %ld\n",
2740 1.1 brezak voice, addr, sc->sc_voc[voice].end_addr));
2741 1.1 brezak /* XXX sanity check the address? */
2742 1.1 brezak
2743 1.87 kent return addr;
2744 1.1 brezak }
2745 1.14 christos #endif
2746 1.1 brezak
2747 1.1 brezak /*
2748 1.1 brezak * Convert an address value to a "16 bit" value - why this is necessary I
2749 1.1 brezak * have NO idea
2750 1.1 brezak */
2751 1.1 brezak
2752 1.14 christos STATIC u_long
2753 1.87 kent convert_to_16bit(u_long address)
2754 1.1 brezak {
2755 1.14 christos u_long old_address;
2756 1.1 brezak
2757 1.1 brezak old_address = address;
2758 1.1 brezak address >>= 1;
2759 1.1 brezak address &= 0x0001ffffL;
2760 1.1 brezak address |= (old_address & 0x000c0000L);
2761 1.1 brezak
2762 1.87 kent return address;
2763 1.1 brezak }
2764 1.1 brezak
2765 1.1 brezak /*
2766 1.1 brezak * Write a value into the GUS's DRAM
2767 1.1 brezak */
2768 1.8 jtk STATIC void
2769 1.87 kent guspoke(bus_space_tag_t iot, bus_space_handle_t ioh2,
2770 1.87 kent long address, unsigned char value)
2771 1.1 brezak {
2772 1.1 brezak
2773 1.1 brezak /*
2774 1.1 brezak * Select the DRAM address
2775 1.1 brezak */
2776 1.1 brezak
2777 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DRAM_ADDR_LOW);
2778 1.110 msaitoh bus_space_write_2(iot, ioh2, GUS_DATA_LOW,
2779 1.110 msaitoh (unsigned int)(address & 0xffff));
2780 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DRAM_ADDR_HIGH);
2781 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2782 1.110 msaitoh (unsigned char)((address >> 16) & 0xff));
2783 1.1 brezak
2784 1.1 brezak /*
2785 1.1 brezak * Actually write the data
2786 1.1 brezak */
2787 1.1 brezak
2788 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DRAM_DATA, value);
2789 1.1 brezak }
2790 1.1 brezak
2791 1.1 brezak /*
2792 1.1 brezak * Read a value from the GUS's DRAM
2793 1.1 brezak */
2794 1.8 jtk STATIC unsigned char
2795 1.87 kent guspeek(bus_space_tag_t iot, bus_space_handle_t ioh2, u_long address)
2796 1.1 brezak {
2797 1.1 brezak
2798 1.1 brezak /*
2799 1.1 brezak * Select the DRAM address
2800 1.1 brezak */
2801 1.1 brezak
2802 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DRAM_ADDR_LOW);
2803 1.110 msaitoh bus_space_write_2(iot, ioh2, GUS_DATA_LOW,
2804 1.110 msaitoh (unsigned int)(address & 0xffff));
2805 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DRAM_ADDR_HIGH);
2806 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2807 1.110 msaitoh (unsigned char)((address >> 16) & 0xff));
2808 1.1 brezak
2809 1.1 brezak /*
2810 1.1 brezak * Read in the data from the board
2811 1.1 brezak */
2812 1.1 brezak
2813 1.43 augustss return (unsigned char) bus_space_read_1(iot, ioh2, GUS_DRAM_DATA);
2814 1.1 brezak }
2815 1.1 brezak
2816 1.1 brezak /*
2817 1.1 brezak * Reset the Gravis UltraSound card, completely
2818 1.1 brezak */
2819 1.8 jtk STATIC void
2820 1.87 kent gusreset(struct gus_softc *sc, int voices)
2821 1.1 brezak {
2822 1.87 kent bus_space_tag_t iot;
2823 1.87 kent bus_space_handle_t ioh1;
2824 1.87 kent bus_space_handle_t ioh2;
2825 1.87 kent bus_space_handle_t ioh4;
2826 1.107 jmcneill int i;
2827 1.107 jmcneill
2828 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
2829 1.1 brezak
2830 1.87 kent iot = sc->sc_iot;
2831 1.87 kent ioh1 = sc->sc_ioh1;
2832 1.87 kent ioh2 = sc->sc_ioh2;
2833 1.87 kent ioh4 = sc->sc_ioh4;
2834 1.1 brezak
2835 1.1 brezak /*
2836 1.1 brezak * Reset the GF1 chip
2837 1.1 brezak */
2838 1.1 brezak
2839 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
2840 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2841 1.1 brezak
2842 1.1 brezak delay(500);
2843 1.1 brezak
2844 1.1 brezak /*
2845 1.1 brezak * Release reset
2846 1.1 brezak */
2847 1.1 brezak
2848 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
2849 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, GUSMASK_MASTER_RESET);
2850 1.1 brezak
2851 1.1 brezak delay(500);
2852 1.1 brezak
2853 1.1 brezak /*
2854 1.1 brezak * Reset MIDI port as well
2855 1.1 brezak */
2856 1.1 brezak
2857 1.43 augustss bus_space_write_1(iot, ioh4, GUS_MIDI_CONTROL, MIDI_RESET);
2858 1.1 brezak
2859 1.1 brezak delay(500);
2860 1.1 brezak
2861 1.43 augustss bus_space_write_1(iot, ioh4, GUS_MIDI_CONTROL, 0x00);
2862 1.1 brezak
2863 1.1 brezak /*
2864 1.1 brezak * Clear interrupts
2865 1.1 brezak */
2866 1.1 brezak
2867 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
2868 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2869 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_TIMER_CONTROL);
2870 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2871 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
2872 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x00);
2873 1.1 brezak
2874 1.1 brezak gus_set_voices(sc, voices);
2875 1.1 brezak
2876 1.43 augustss bus_space_read_1(iot, ioh1, GUS_IRQ_STATUS);
2877 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
2878 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2879 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
2880 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2881 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_IRQ_STATUS);
2882 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2883 1.1 brezak
2884 1.1 brezak /*
2885 1.1 brezak * Reset voice specific information
2886 1.1 brezak */
2887 1.1 brezak
2888 1.1 brezak for(i = 0; i < voices; i++) {
2889 1.43 augustss bus_space_write_1(iot, ioh2, GUS_VOICE_SELECT, (unsigned char) i);
2890 1.1 brezak
2891 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOICE_CNTL);
2892 1.1 brezak
2893 1.1 brezak sc->sc_voc[i].voccntl = GUSMASK_VOICE_STOPPED |
2894 1.1 brezak GUSMASK_STOP_VOICE;
2895 1.1 brezak
2896 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[i].voccntl);
2897 1.1 brezak
2898 1.1 brezak sc->sc_voc[i].volcntl = GUSMASK_VOLUME_STOPPED |
2899 1.1 brezak GUSMASK_STOP_VOLUME;
2900 1.1 brezak
2901 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_CONTROL);
2902 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, sc->sc_voc[i].volcntl);
2903 1.1 brezak
2904 1.1 brezak delay(100);
2905 1.1 brezak
2906 1.1 brezak gus_set_samprate(sc, i, 8000);
2907 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_ADDR_HIGH);
2908 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2909 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_ADDR_LOW);
2910 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2911 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_HIGH);
2912 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2913 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_ADDR_LOW);
2914 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2915 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_VOLUME_RATE);
2916 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x01);
2917 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_START_VOLUME);
2918 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x10);
2919 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_END_VOLUME);
2920 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0xe0);
2921 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_VOLUME);
2922 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2923 1.43 augustss
2924 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_HIGH);
2925 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2926 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_CUR_ADDR_LOW);
2927 1.43 augustss bus_space_write_2(iot, ioh2, GUS_DATA_LOW, 0x0000);
2928 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_PAN_POS);
2929 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0x07);
2930 1.1 brezak }
2931 1.1 brezak
2932 1.1 brezak /*
2933 1.1 brezak * Clear out any pending IRQs
2934 1.1 brezak */
2935 1.1 brezak
2936 1.43 augustss bus_space_read_1(iot, ioh1, GUS_IRQ_STATUS);
2937 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
2938 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2939 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
2940 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2941 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_IRQ_STATUS);
2942 1.43 augustss bus_space_read_1(iot, ioh2, GUS_DATA_HIGH);
2943 1.1 brezak
2944 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_RESET);
2945 1.110 msaitoh bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
2946 1.110 msaitoh GUSMASK_MASTER_RESET | GUSMASK_DAC_ENABLE | GUSMASK_IRQ_ENABLE);
2947 1.1 brezak }
2948 1.1 brezak
2949 1.1 brezak
2950 1.51 mycroft STATIC int
2951 1.87 kent gus_init_cs4231(struct gus_softc *sc)
2952 1.1 brezak {
2953 1.87 kent bus_space_tag_t iot;
2954 1.87 kent bus_space_handle_t ioh1;
2955 1.87 kent int port;
2956 1.1 brezak u_char ctrl;
2957 1.1 brezak
2958 1.87 kent iot = sc->sc_iot;
2959 1.87 kent ioh1 = sc->sc_ioh1;
2960 1.87 kent port = sc->sc_iobase;
2961 1.1 brezak ctrl = (port & 0xf0) >> 4; /* set port address middle nibble */
2962 1.1 brezak /*
2963 1.80 wiz * The codec is a bit weird--swapped DMA channels.
2964 1.1 brezak */
2965 1.1 brezak ctrl |= GUS_MAX_CODEC_ENABLE;
2966 1.66 mycroft if (sc->sc_playdrq >= 4)
2967 1.1 brezak ctrl |= GUS_MAX_RECCHAN16;
2968 1.1 brezak if (sc->sc_recdrq >= 4)
2969 1.1 brezak ctrl |= GUS_MAX_PLAYCHAN16;
2970 1.1 brezak
2971 1.43 augustss bus_space_write_1(iot, ioh1, GUS_MAX_CTRL, ctrl);
2972 1.1 brezak
2973 1.60 pk sc->sc_codec.sc_ad1848.sc_iot = sc->sc_iot;
2974 1.1 brezak sc->sc_codec.sc_iobase = port+GUS_MAX_CODEC_BASE;
2975 1.1 brezak
2976 1.60 pk if (ad1848_isa_mapprobe(&sc->sc_codec, sc->sc_codec.sc_iobase) == 0) {
2977 1.1 brezak sc->sc_flags &= ~GUS_CODEC_INSTALLED;
2978 1.87 kent return 0;
2979 1.1 brezak } else {
2980 1.1 brezak struct ad1848_volume vol = {AUDIO_MAX_GAIN, AUDIO_MAX_GAIN};
2981 1.1 brezak sc->sc_flags |= GUS_CODEC_INSTALLED;
2982 1.60 pk sc->sc_codec.sc_ad1848.parent = sc;
2983 1.66 mycroft sc->sc_codec.sc_playdrq = sc->sc_recdrq;
2984 1.68 thorpej sc->sc_codec.sc_play_maxsize = sc->sc_req_maxsize;
2985 1.66 mycroft sc->sc_codec.sc_recdrq = sc->sc_playdrq;
2986 1.68 thorpej sc->sc_codec.sc_rec_maxsize = sc->sc_play_maxsize;
2987 1.1 brezak /* enable line in and mic in the GUS mixer; the codec chip
2988 1.1 brezak will do the real mixing for them. */
2989 1.1 brezak sc->sc_mixcontrol &= ~GUSMASK_LINE_IN; /* 0 enables. */
2990 1.1 brezak sc->sc_mixcontrol |= GUSMASK_MIC_IN; /* 1 enables. */
2991 1.110 msaitoh bus_space_write_1(iot, ioh1, GUS_MIX_CONTROL,
2992 1.110 msaitoh sc->sc_mixcontrol);
2993 1.87 kent
2994 1.61 jtk ad1848_isa_attach(&sc->sc_codec);
2995 1.1 brezak /* turn on pre-MUX microphone gain. */
2996 1.60 pk ad1848_set_mic_gain(&sc->sc_codec.sc_ad1848, &vol);
2997 1.51 mycroft
2998 1.87 kent return 1;
2999 1.1 brezak }
3000 1.1 brezak }
3001 1.1 brezak
3002 1.1 brezak
3003 1.1 brezak /*
3004 1.1 brezak * Return info about the audio device, for the AUDIO_GETINFO ioctl
3005 1.1 brezak */
3006 1.1 brezak int
3007 1.96 christos gus_getdev(void *addr, struct audio_device *dev)
3008 1.1 brezak {
3009 1.87 kent
3010 1.1 brezak *dev = gus_device;
3011 1.1 brezak return 0;
3012 1.1 brezak }
3013 1.1 brezak
3014 1.1 brezak /*
3015 1.1 brezak * stubs (XXX)
3016 1.1 brezak */
3017 1.1 brezak
3018 1.1 brezak int
3019 1.97 christos gus_set_in_gain(void *addr, u_int gain,
3020 1.96 christos u_char balance)
3021 1.1 brezak {
3022 1.87 kent
3023 1.1 brezak DPRINTF(("gus_set_in_gain called\n"));
3024 1.1 brezak return 0;
3025 1.1 brezak }
3026 1.1 brezak
3027 1.1 brezak int
3028 1.97 christos gus_get_in_gain(void *addr)
3029 1.1 brezak {
3030 1.87 kent
3031 1.1 brezak DPRINTF(("gus_get_in_gain called\n"));
3032 1.1 brezak return 0;
3033 1.1 brezak }
3034 1.1 brezak
3035 1.1 brezak int
3036 1.89 christos gusmax_dma_input(void *addr, void *tbuf, int size,
3037 1.87 kent void (*callback)(void *), void *arg)
3038 1.1 brezak {
3039 1.87 kent struct ad1848_isa_softc *sc;
3040 1.87 kent
3041 1.87 kent sc = addr;
3042 1.89 christos return gus_dma_input(sc->sc_ad1848.parent, tbuf, size, callback, arg);
3043 1.1 brezak }
3044 1.1 brezak
3045 1.1 brezak /*
3046 1.1 brezak * Start sampling the input source into the requested DMA buffer.
3047 1.107 jmcneill * Called from top-half or from interrupt handler.
3048 1.1 brezak */
3049 1.1 brezak int
3050 1.89 christos gus_dma_input(void *addr, void *tbuf, int size,
3051 1.87 kent void (*callback)(void *), void *arg)
3052 1.1 brezak {
3053 1.87 kent struct gus_softc *sc;
3054 1.87 kent bus_space_tag_t iot;
3055 1.87 kent bus_space_handle_t ioh2;
3056 1.38 augustss u_char dmac;
3057 1.87 kent
3058 1.1 brezak DMAPRINTF(("gus_dma_input called\n"));
3059 1.87 kent sc = addr;
3060 1.87 kent iot = sc->sc_iot;
3061 1.87 kent ioh2 = sc->sc_ioh2;
3062 1.87 kent
3063 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
3064 1.107 jmcneill
3065 1.1 brezak /*
3066 1.1 brezak * Sample SIZE bytes of data from the card, into buffer at BUF.
3067 1.1 brezak */
3068 1.1 brezak
3069 1.1 brezak if (sc->sc_precision == 16)
3070 1.87 kent return EINVAL; /* XXX */
3071 1.1 brezak
3072 1.1 brezak /* set DMA modes */
3073 1.1 brezak dmac = GUSMASK_SAMPLE_IRQ|GUSMASK_SAMPLE_START;
3074 1.1 brezak if (sc->sc_recdrq >= 4)
3075 1.1 brezak dmac |= GUSMASK_SAMPLE_DATA16;
3076 1.1 brezak if (sc->sc_encoding == AUDIO_ENCODING_ULAW ||
3077 1.87 kent sc->sc_encoding == AUDIO_ENCODING_ALAW ||
3078 1.87 kent sc->sc_encoding == AUDIO_ENCODING_ULINEAR_LE ||
3079 1.87 kent sc->sc_encoding == AUDIO_ENCODING_ULINEAR_BE)
3080 1.87 kent dmac |= GUSMASK_SAMPLE_INVBIT;
3081 1.1 brezak if (sc->sc_channels == 2)
3082 1.87 kent dmac |= GUSMASK_SAMPLE_STEREO;
3083 1.89 christos isa_dmastart(sc->sc_ic, sc->sc_recdrq, tbuf, size,
3084 1.87 kent NULL, DMAMODE_READ, BUS_DMA_NOWAIT);
3085 1.1 brezak
3086 1.1 brezak DMAPRINTF(("gus_dma_input isa_dmastarted\n"));
3087 1.1 brezak sc->sc_flags |= GUS_DMAIN_ACTIVE;
3088 1.1 brezak sc->sc_dmainintr = callback;
3089 1.1 brezak sc->sc_inarg = arg;
3090 1.1 brezak sc->sc_dmaincnt = size;
3091 1.89 christos sc->sc_dmainaddr = tbuf;
3092 1.1 brezak
3093 1.43 augustss SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
3094 1.43 augustss bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, dmac); /* Go! */
3095 1.1 brezak
3096 1.1 brezak
3097 1.1 brezak DMAPRINTF(("gus_dma_input returning\n"));
3098 1.1 brezak
3099 1.1 brezak return 0;
3100 1.1 brezak }
3101 1.1 brezak
3102 1.8 jtk STATIC int
3103 1.87 kent gus_dmain_intr(struct gus_softc *sc)
3104 1.1 brezak {
3105 1.87 kent void (*callback)(void *);
3106 1.1 brezak void *arg;
3107 1.1 brezak
3108 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
3109 1.107 jmcneill
3110 1.1 brezak DMAPRINTF(("gus_dmain_intr called\n"));
3111 1.1 brezak if (sc->sc_dmainintr) {
3112 1.87 kent isa_dmadone(sc->sc_ic, sc->sc_recdrq);
3113 1.87 kent callback = sc->sc_dmainintr;
3114 1.87 kent arg = sc->sc_inarg;
3115 1.87 kent
3116 1.87 kent sc->sc_dmainaddr = 0;
3117 1.87 kent sc->sc_dmaincnt = 0;
3118 1.87 kent sc->sc_dmainintr = 0;
3119 1.87 kent sc->sc_inarg = 0;
3120 1.87 kent
3121 1.87 kent sc->sc_flags &= ~GUS_DMAIN_ACTIVE;
3122 1.110 msaitoh DMAPRINTF(("calling dmain_intr callback %p(%p)\n", callback,
3123 1.110 msaitoh arg));
3124 1.87 kent (*callback)(arg);
3125 1.87 kent return 1;
3126 1.1 brezak } else {
3127 1.87 kent DMAPRINTF(("gus_dmain_intr false?\n"));
3128 1.87 kent return 0; /* XXX ??? */
3129 1.1 brezak }
3130 1.1 brezak }
3131 1.1 brezak
3132 1.1 brezak int
3133 1.87 kent gusmax_halt_out_dma(void *addr)
3134 1.1 brezak {
3135 1.87 kent struct ad1848_isa_softc *sc;
3136 1.87 kent
3137 1.87 kent sc = addr;
3138 1.62 jtk return gus_halt_out_dma(sc->sc_ad1848.parent);
3139 1.1 brezak }
3140 1.1 brezak
3141 1.1 brezak
3142 1.1 brezak int
3143 1.87 kent gusmax_halt_in_dma(void *addr)
3144 1.1 brezak {
3145 1.87 kent struct ad1848_isa_softc *sc;
3146 1.87 kent
3147 1.87 kent sc = addr;
3148 1.62 jtk return gus_halt_in_dma(sc->sc_ad1848.parent);
3149 1.1 brezak }
3150 1.1 brezak
3151 1.1 brezak /*
3152 1.107 jmcneill * Stop any DMA output.
3153 1.1 brezak */
3154 1.1 brezak int
3155 1.87 kent gus_halt_out_dma(void *addr)
3156 1.1 brezak {
3157 1.87 kent struct gus_softc *sc;
3158 1.87 kent bus_space_tag_t iot;
3159 1.87 kent bus_space_handle_t ioh2;
3160 1.1 brezak
3161 1.1 brezak DMAPRINTF(("gus_halt_out_dma called\n"));
3162 1.87 kent sc = addr;
3163 1.87 kent iot = sc->sc_iot;
3164 1.87 kent ioh2 = sc->sc_ioh2;
3165 1.107 jmcneill
3166 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
3167 1.107 jmcneill
3168 1.1 brezak /*
3169 1.1 brezak * Make sure the GUS _isn't_ setup for DMA
3170 1.1 brezak */
3171 1.1 brezak
3172 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_DMA_CONTROL);
3173 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH, 0);
3174 1.1 brezak
3175 1.69 thorpej callout_stop(&sc->sc_dmaout_ch);
3176 1.87 kent isa_dmaabort(sc->sc_ic, sc->sc_playdrq);
3177 1.1 brezak sc->sc_flags &= ~(GUS_DMAOUT_ACTIVE|GUS_LOCKED);
3178 1.1 brezak sc->sc_dmaoutintr = 0;
3179 1.1 brezak sc->sc_outarg = 0;
3180 1.1 brezak sc->sc_dmaoutaddr = 0;
3181 1.1 brezak sc->sc_dmaoutcnt = 0;
3182 1.1 brezak sc->sc_dmabuf = 0;
3183 1.1 brezak sc->sc_bufcnt = 0;
3184 1.1 brezak sc->sc_playbuf = -1;
3185 1.1 brezak /* also stop playing */
3186 1.1 brezak gus_stop_voice(sc, GUS_VOICE_LEFT, 1);
3187 1.1 brezak gus_stop_voice(sc, GUS_VOICE_RIGHT, 0);
3188 1.1 brezak
3189 1.1 brezak return 0;
3190 1.1 brezak }
3191 1.1 brezak
3192 1.1 brezak /*
3193 1.107 jmcneill * Stop any DMA output.
3194 1.1 brezak */
3195 1.1 brezak int
3196 1.87 kent gus_halt_in_dma(void *addr)
3197 1.1 brezak {
3198 1.87 kent struct gus_softc *sc;
3199 1.87 kent bus_space_tag_t iot;
3200 1.87 kent bus_space_handle_t ioh2;
3201 1.87 kent
3202 1.1 brezak DMAPRINTF(("gus_halt_in_dma called\n"));
3203 1.87 kent sc = addr;
3204 1.87 kent iot = sc->sc_iot;
3205 1.87 kent ioh2 = sc->sc_ioh2;
3206 1.1 brezak
3207 1.107 jmcneill KASSERT(mutex_owned(&sc->sc_codec.sc_ad1848.sc_intr_lock));
3208 1.107 jmcneill
3209 1.1 brezak /*
3210 1.1 brezak * Make sure the GUS _isn't_ setup for DMA
3211 1.1 brezak */
3212 1.1 brezak
3213 1.87 kent SELECT_GUS_REG(iot, ioh2, GUSREG_SAMPLE_CONTROL);
3214 1.87 kent bus_space_write_1(iot, ioh2, GUS_DATA_HIGH,
3215 1.87 kent bus_space_read_1(iot, ioh2, GUS_DATA_HIGH)
3216 1.87 kent & ~(GUSMASK_SAMPLE_START|GUSMASK_SAMPLE_IRQ));
3217 1.87 kent
3218 1.87 kent isa_dmaabort(sc->sc_ic, sc->sc_recdrq);
3219 1.1 brezak sc->sc_flags &= ~GUS_DMAIN_ACTIVE;
3220 1.1 brezak sc->sc_dmainintr = 0;
3221 1.1 brezak sc->sc_inarg = 0;
3222 1.1 brezak sc->sc_dmainaddr = 0;
3223 1.1 brezak sc->sc_dmaincnt = 0;
3224 1.1 brezak
3225 1.1 brezak return 0;
3226 1.1 brezak }
3227 1.1 brezak
3228 1.1 brezak
3229 1.113 maxv static const ad1848_devmap_t gusmapping[] = {
3230 1.58 mycroft { GUSMAX_DAC_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
3231 1.58 mycroft { GUSMAX_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL },
3232 1.58 mycroft { GUSMAX_MONO_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
3233 1.58 mycroft { GUSMAX_CD_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
3234 1.58 mycroft { GUSMAX_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL },
3235 1.58 mycroft { GUSMAX_OUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
3236 1.58 mycroft { GUSMAX_DAC_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
3237 1.58 mycroft { GUSMAX_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL },
3238 1.58 mycroft { GUSMAX_MONO_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
3239 1.58 mycroft { GUSMAX_CD_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
3240 1.58 mycroft { GUSMAX_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL },
3241 1.58 mycroft { GUSMAX_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
3242 1.58 mycroft { GUSMAX_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1 }
3243 1.54 augustss };
3244 1.54 augustss
3245 1.113 maxv static const int nummap = sizeof(gusmapping) / sizeof(gusmapping[0]);
3246 1.1 brezak
3247 1.8 jtk STATIC int
3248 1.87 kent gusmax_mixer_get_port(void *addr, mixer_ctrl_t *cp)
3249 1.1 brezak {
3250 1.87 kent struct ad1848_isa_softc *ac;
3251 1.87 kent struct gus_softc *sc;
3252 1.1 brezak struct ad1848_volume vol;
3253 1.87 kent int error;
3254 1.87 kent
3255 1.87 kent ac = addr;
3256 1.87 kent sc = ac->sc_ad1848.parent;
3257 1.87 kent error = ad1848_mixer_get_port(&ac->sc_ad1848, gusmapping, nummap, cp);
3258 1.54 augustss if (error != ENXIO)
3259 1.87 kent return error;
3260 1.54 augustss
3261 1.54 augustss error = EINVAL;
3262 1.1 brezak
3263 1.1 brezak switch (cp->dev) {
3264 1.1 brezak case GUSMAX_SPEAKER_LVL: /* fake speaker for mute naming */
3265 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3266 1.1 brezak if (sc->sc_mixcontrol & GUSMASK_LINE_OUT)
3267 1.1 brezak vol.left = vol.right = AUDIO_MAX_GAIN;
3268 1.1 brezak else
3269 1.1 brezak vol.left = vol.right = AUDIO_MIN_GAIN;
3270 1.1 brezak error = 0;
3271 1.54 augustss ad1848_from_vol(cp, &vol);
3272 1.1 brezak }
3273 1.1 brezak break;
3274 1.1 brezak
3275 1.1 brezak case GUSMAX_SPEAKER_MUTE:
3276 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3277 1.1 brezak cp->un.ord = sc->sc_mixcontrol & GUSMASK_LINE_OUT ? 1 : 0;
3278 1.1 brezak error = 0;
3279 1.1 brezak }
3280 1.1 brezak break;
3281 1.1 brezak default:
3282 1.1 brezak error = ENXIO;
3283 1.1 brezak break;
3284 1.1 brezak }
3285 1.1 brezak
3286 1.87 kent return error;
3287 1.1 brezak }
3288 1.1 brezak
3289 1.8 jtk STATIC int
3290 1.87 kent gus_mixer_get_port(void *addr, mixer_ctrl_t *cp)
3291 1.1 brezak {
3292 1.87 kent struct gus_softc *sc;
3293 1.87 kent struct ics2101_softc *ic;
3294 1.1 brezak struct ad1848_volume vol;
3295 1.87 kent int error;
3296 1.1 brezak
3297 1.1 brezak DPRINTF(("gus_mixer_get_port: dev=%d type=%d\n", cp->dev, cp->type));
3298 1.87 kent sc = addr;
3299 1.87 kent ic = &sc->sc_mixer;
3300 1.87 kent error = EINVAL;
3301 1.1 brezak
3302 1.1 brezak if (!HAS_MIXER(sc) && cp->dev > GUSICS_MASTER_MUTE)
3303 1.1 brezak return ENXIO;
3304 1.87 kent
3305 1.1 brezak switch (cp->dev) {
3306 1.1 brezak
3307 1.1 brezak case GUSICS_MIC_IN_MUTE: /* Microphone */
3308 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3309 1.1 brezak if (HAS_MIXER(sc))
3310 1.1 brezak cp->un.ord = ic->sc_mute[GUSMIX_CHAN_MIC][ICSMIX_LEFT];
3311 1.1 brezak else
3312 1.1 brezak cp->un.ord =
3313 1.1 brezak sc->sc_mixcontrol & GUSMASK_MIC_IN ? 0 : 1;
3314 1.1 brezak error = 0;
3315 1.1 brezak }
3316 1.1 brezak break;
3317 1.1 brezak
3318 1.1 brezak case GUSICS_LINE_IN_MUTE:
3319 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3320 1.1 brezak if (HAS_MIXER(sc))
3321 1.1 brezak cp->un.ord = ic->sc_mute[GUSMIX_CHAN_LINE][ICSMIX_LEFT];
3322 1.1 brezak else
3323 1.1 brezak cp->un.ord =
3324 1.1 brezak sc->sc_mixcontrol & GUSMASK_LINE_IN ? 1 : 0;
3325 1.1 brezak error = 0;
3326 1.1 brezak }
3327 1.1 brezak break;
3328 1.1 brezak
3329 1.1 brezak case GUSICS_MASTER_MUTE:
3330 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3331 1.1 brezak if (HAS_MIXER(sc))
3332 1.1 brezak cp->un.ord = ic->sc_mute[GUSMIX_CHAN_MASTER][ICSMIX_LEFT];
3333 1.1 brezak else
3334 1.1 brezak cp->un.ord =
3335 1.1 brezak sc->sc_mixcontrol & GUSMASK_LINE_OUT ? 1 : 0;
3336 1.1 brezak error = 0;
3337 1.1 brezak }
3338 1.1 brezak break;
3339 1.1 brezak
3340 1.1 brezak case GUSICS_DAC_MUTE:
3341 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3342 1.1 brezak cp->un.ord = ic->sc_mute[GUSMIX_CHAN_DAC][ICSMIX_LEFT];
3343 1.1 brezak error = 0;
3344 1.1 brezak }
3345 1.1 brezak break;
3346 1.1 brezak
3347 1.1 brezak case GUSICS_CD_MUTE:
3348 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3349 1.1 brezak cp->un.ord = ic->sc_mute[GUSMIX_CHAN_CD][ICSMIX_LEFT];
3350 1.1 brezak error = 0;
3351 1.1 brezak }
3352 1.1 brezak break;
3353 1.1 brezak
3354 1.1 brezak case GUSICS_MASTER_LVL:
3355 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3356 1.1 brezak vol.left = ic->sc_setting[GUSMIX_CHAN_MASTER][ICSMIX_LEFT];
3357 1.1 brezak vol.right = ic->sc_setting[GUSMIX_CHAN_MASTER][ICSMIX_RIGHT];
3358 1.54 augustss if (ad1848_from_vol(cp, &vol))
3359 1.1 brezak error = 0;
3360 1.1 brezak }
3361 1.1 brezak break;
3362 1.1 brezak
3363 1.1 brezak case GUSICS_MIC_IN_LVL: /* Microphone */
3364 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3365 1.1 brezak vol.left = ic->sc_setting[GUSMIX_CHAN_MIC][ICSMIX_LEFT];
3366 1.1 brezak vol.right = ic->sc_setting[GUSMIX_CHAN_MIC][ICSMIX_RIGHT];
3367 1.54 augustss if (ad1848_from_vol(cp, &vol))
3368 1.1 brezak error = 0;
3369 1.1 brezak }
3370 1.1 brezak break;
3371 1.87 kent
3372 1.1 brezak case GUSICS_LINE_IN_LVL: /* line in */
3373 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3374 1.1 brezak vol.left = ic->sc_setting[GUSMIX_CHAN_LINE][ICSMIX_LEFT];
3375 1.1 brezak vol.right = ic->sc_setting[GUSMIX_CHAN_LINE][ICSMIX_RIGHT];
3376 1.54 augustss if (ad1848_from_vol(cp, &vol))
3377 1.1 brezak error = 0;
3378 1.1 brezak }
3379 1.1 brezak break;
3380 1.1 brezak
3381 1.1 brezak
3382 1.1 brezak case GUSICS_CD_LVL:
3383 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3384 1.1 brezak vol.left = ic->sc_setting[GUSMIX_CHAN_CD][ICSMIX_LEFT];
3385 1.1 brezak vol.right = ic->sc_setting[GUSMIX_CHAN_CD][ICSMIX_RIGHT];
3386 1.54 augustss if (ad1848_from_vol(cp, &vol))
3387 1.1 brezak error = 0;
3388 1.1 brezak }
3389 1.1 brezak break;
3390 1.1 brezak
3391 1.1 brezak case GUSICS_DAC_LVL: /* dac out */
3392 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3393 1.1 brezak vol.left = ic->sc_setting[GUSMIX_CHAN_DAC][ICSMIX_LEFT];
3394 1.1 brezak vol.right = ic->sc_setting[GUSMIX_CHAN_DAC][ICSMIX_RIGHT];
3395 1.54 augustss if (ad1848_from_vol(cp, &vol))
3396 1.1 brezak error = 0;
3397 1.1 brezak }
3398 1.1 brezak break;
3399 1.1 brezak
3400 1.1 brezak
3401 1.1 brezak case GUSICS_RECORD_SOURCE:
3402 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3403 1.1 brezak /* Can't set anything else useful, sigh. */
3404 1.1 brezak cp->un.ord = 0;
3405 1.1 brezak }
3406 1.1 brezak break;
3407 1.1 brezak
3408 1.1 brezak default:
3409 1.1 brezak return ENXIO;
3410 1.87 kent /*NOTREACHED*/
3411 1.1 brezak }
3412 1.1 brezak return error;
3413 1.1 brezak }
3414 1.1 brezak
3415 1.8 jtk STATIC void
3416 1.87 kent gusics_master_mute(struct ics2101_softc *ic, int mute)
3417 1.1 brezak {
3418 1.87 kent
3419 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_MASTER, ICSMIX_LEFT, mute);
3420 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_MASTER, ICSMIX_RIGHT, mute);
3421 1.1 brezak }
3422 1.1 brezak
3423 1.8 jtk STATIC void
3424 1.87 kent gusics_mic_mute(struct ics2101_softc *ic, int mute)
3425 1.1 brezak {
3426 1.87 kent
3427 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_MIC, ICSMIX_LEFT, mute);
3428 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_MIC, ICSMIX_RIGHT, mute);
3429 1.1 brezak }
3430 1.1 brezak
3431 1.8 jtk STATIC void
3432 1.87 kent gusics_linein_mute(struct ics2101_softc *ic, int mute)
3433 1.1 brezak {
3434 1.87 kent
3435 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_LINE, ICSMIX_LEFT, mute);
3436 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_LINE, ICSMIX_RIGHT, mute);
3437 1.1 brezak }
3438 1.1 brezak
3439 1.8 jtk STATIC void
3440 1.87 kent gusics_cd_mute(struct ics2101_softc *ic, int mute)
3441 1.1 brezak {
3442 1.87 kent
3443 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_CD, ICSMIX_LEFT, mute);
3444 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_CD, ICSMIX_RIGHT, mute);
3445 1.1 brezak }
3446 1.1 brezak
3447 1.8 jtk STATIC void
3448 1.87 kent gusics_dac_mute(struct ics2101_softc *ic, int mute)
3449 1.1 brezak {
3450 1.87 kent
3451 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_DAC, ICSMIX_LEFT, mute);
3452 1.1 brezak ics2101_mix_mute(ic, GUSMIX_CHAN_DAC, ICSMIX_RIGHT, mute);
3453 1.1 brezak }
3454 1.1 brezak
3455 1.8 jtk STATIC int
3456 1.87 kent gusmax_mixer_set_port(void *addr, mixer_ctrl_t *cp)
3457 1.1 brezak {
3458 1.87 kent struct ad1848_isa_softc *ac;
3459 1.87 kent struct gus_softc *sc;
3460 1.1 brezak struct ad1848_volume vol;
3461 1.87 kent int error;
3462 1.87 kent
3463 1.87 kent ac = addr;
3464 1.87 kent sc = ac->sc_ad1848.parent;
3465 1.87 kent error = ad1848_mixer_set_port(&ac->sc_ad1848, gusmapping, nummap, cp);
3466 1.54 augustss if (error != ENXIO)
3467 1.87 kent return error;
3468 1.54 augustss
3469 1.1 brezak DPRINTF(("gusmax_mixer_set_port: dev=%d type=%d\n", cp->dev, cp->type));
3470 1.1 brezak
3471 1.1 brezak switch (cp->dev) {
3472 1.1 brezak case GUSMAX_SPEAKER_LVL:
3473 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE &&
3474 1.1 brezak cp->un.value.num_channels == 1) {
3475 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3476 1.1 brezak gus_speaker_ctl(sc, vol.left > AUDIO_MIN_GAIN ?
3477 1.1 brezak SPKR_ON : SPKR_OFF);
3478 1.1 brezak error = 0;
3479 1.1 brezak }
3480 1.1 brezak }
3481 1.1 brezak break;
3482 1.1 brezak
3483 1.1 brezak case GUSMAX_SPEAKER_MUTE:
3484 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3485 1.1 brezak gus_speaker_ctl(sc, cp->un.ord ? SPKR_OFF : SPKR_ON);
3486 1.1 brezak error = 0;
3487 1.1 brezak }
3488 1.1 brezak break;
3489 1.1 brezak
3490 1.1 brezak default:
3491 1.1 brezak return ENXIO;
3492 1.87 kent /*NOTREACHED*/
3493 1.87 kent }
3494 1.87 kent return error;
3495 1.1 brezak }
3496 1.1 brezak
3497 1.8 jtk STATIC int
3498 1.87 kent gus_mixer_set_port(void *addr, mixer_ctrl_t *cp)
3499 1.1 brezak {
3500 1.87 kent struct gus_softc *sc;
3501 1.87 kent struct ics2101_softc *ic;
3502 1.1 brezak struct ad1848_volume vol;
3503 1.87 kent int error;
3504 1.1 brezak
3505 1.1 brezak DPRINTF(("gus_mixer_set_port: dev=%d type=%d\n", cp->dev, cp->type));
3506 1.87 kent sc = addr;
3507 1.87 kent ic = &sc->sc_mixer;
3508 1.87 kent error = EINVAL;
3509 1.1 brezak
3510 1.1 brezak if (!HAS_MIXER(sc) && cp->dev > GUSICS_MASTER_MUTE)
3511 1.1 brezak return ENXIO;
3512 1.87 kent
3513 1.1 brezak switch (cp->dev) {
3514 1.1 brezak
3515 1.1 brezak case GUSICS_MIC_IN_MUTE: /* Microphone */
3516 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3517 1.1 brezak DPRINTF(("mic mute %d\n", cp->un.ord));
3518 1.1 brezak if (HAS_MIXER(sc)) {
3519 1.1 brezak gusics_mic_mute(ic, cp->un.ord);
3520 1.1 brezak }
3521 1.1 brezak gus_mic_ctl(sc, cp->un.ord ? SPKR_OFF : SPKR_ON);
3522 1.1 brezak error = 0;
3523 1.1 brezak }
3524 1.1 brezak break;
3525 1.1 brezak
3526 1.1 brezak case GUSICS_LINE_IN_MUTE:
3527 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3528 1.1 brezak DPRINTF(("linein mute %d\n", cp->un.ord));
3529 1.1 brezak if (HAS_MIXER(sc)) {
3530 1.1 brezak gusics_linein_mute(ic, cp->un.ord);
3531 1.1 brezak }
3532 1.1 brezak gus_linein_ctl(sc, cp->un.ord ? SPKR_OFF : SPKR_ON);
3533 1.1 brezak error = 0;
3534 1.1 brezak }
3535 1.1 brezak break;
3536 1.1 brezak
3537 1.1 brezak case GUSICS_MASTER_MUTE:
3538 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3539 1.1 brezak DPRINTF(("master mute %d\n", cp->un.ord));
3540 1.1 brezak if (HAS_MIXER(sc)) {
3541 1.1 brezak gusics_master_mute(ic, cp->un.ord);
3542 1.1 brezak }
3543 1.1 brezak gus_speaker_ctl(sc, cp->un.ord ? SPKR_OFF : SPKR_ON);
3544 1.1 brezak error = 0;
3545 1.1 brezak }
3546 1.1 brezak break;
3547 1.1 brezak
3548 1.1 brezak case GUSICS_DAC_MUTE:
3549 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3550 1.1 brezak gusics_dac_mute(ic, cp->un.ord);
3551 1.1 brezak error = 0;
3552 1.1 brezak }
3553 1.1 brezak break;
3554 1.1 brezak
3555 1.1 brezak case GUSICS_CD_MUTE:
3556 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM) {
3557 1.1 brezak gusics_cd_mute(ic, cp->un.ord);
3558 1.1 brezak error = 0;
3559 1.1 brezak }
3560 1.1 brezak break;
3561 1.1 brezak
3562 1.1 brezak case GUSICS_MASTER_LVL:
3563 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3564 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3565 1.1 brezak ics2101_mix_attenuate(ic,
3566 1.1 brezak GUSMIX_CHAN_MASTER,
3567 1.1 brezak ICSMIX_LEFT,
3568 1.1 brezak vol.left);
3569 1.1 brezak ics2101_mix_attenuate(ic,
3570 1.1 brezak GUSMIX_CHAN_MASTER,
3571 1.1 brezak ICSMIX_RIGHT,
3572 1.1 brezak vol.right);
3573 1.1 brezak error = 0;
3574 1.1 brezak }
3575 1.1 brezak }
3576 1.1 brezak break;
3577 1.1 brezak
3578 1.1 brezak case GUSICS_MIC_IN_LVL: /* Microphone */
3579 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3580 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3581 1.1 brezak ics2101_mix_attenuate(ic,
3582 1.1 brezak GUSMIX_CHAN_MIC,
3583 1.1 brezak ICSMIX_LEFT,
3584 1.1 brezak vol.left);
3585 1.1 brezak ics2101_mix_attenuate(ic,
3586 1.1 brezak GUSMIX_CHAN_MIC,
3587 1.1 brezak ICSMIX_RIGHT,
3588 1.1 brezak vol.right);
3589 1.1 brezak error = 0;
3590 1.1 brezak }
3591 1.1 brezak }
3592 1.1 brezak break;
3593 1.87 kent
3594 1.1 brezak case GUSICS_LINE_IN_LVL: /* line in */
3595 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3596 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3597 1.1 brezak ics2101_mix_attenuate(ic,
3598 1.1 brezak GUSMIX_CHAN_LINE,
3599 1.1 brezak ICSMIX_LEFT,
3600 1.1 brezak vol.left);
3601 1.1 brezak ics2101_mix_attenuate(ic,
3602 1.1 brezak GUSMIX_CHAN_LINE,
3603 1.1 brezak ICSMIX_RIGHT,
3604 1.1 brezak vol.right);
3605 1.1 brezak error = 0;
3606 1.1 brezak }
3607 1.1 brezak }
3608 1.1 brezak break;
3609 1.1 brezak
3610 1.1 brezak
3611 1.1 brezak case GUSICS_CD_LVL:
3612 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3613 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3614 1.1 brezak ics2101_mix_attenuate(ic,
3615 1.1 brezak GUSMIX_CHAN_CD,
3616 1.1 brezak ICSMIX_LEFT,
3617 1.1 brezak vol.left);
3618 1.1 brezak ics2101_mix_attenuate(ic,
3619 1.1 brezak GUSMIX_CHAN_CD,
3620 1.1 brezak ICSMIX_RIGHT,
3621 1.1 brezak vol.right);
3622 1.1 brezak error = 0;
3623 1.1 brezak }
3624 1.1 brezak }
3625 1.1 brezak break;
3626 1.1 brezak
3627 1.1 brezak case GUSICS_DAC_LVL: /* dac out */
3628 1.1 brezak if (cp->type == AUDIO_MIXER_VALUE) {
3629 1.54 augustss if (ad1848_to_vol(cp, &vol)) {
3630 1.1 brezak ics2101_mix_attenuate(ic,
3631 1.1 brezak GUSMIX_CHAN_DAC,
3632 1.1 brezak ICSMIX_LEFT,
3633 1.1 brezak vol.left);
3634 1.1 brezak ics2101_mix_attenuate(ic,
3635 1.1 brezak GUSMIX_CHAN_DAC,
3636 1.1 brezak ICSMIX_RIGHT,
3637 1.1 brezak vol.right);
3638 1.1 brezak error = 0;
3639 1.1 brezak }
3640 1.1 brezak }
3641 1.1 brezak break;
3642 1.1 brezak
3643 1.1 brezak
3644 1.1 brezak case GUSICS_RECORD_SOURCE:
3645 1.1 brezak if (cp->type == AUDIO_MIXER_ENUM && cp->un.ord == 0) {
3646 1.1 brezak /* Can't set anything else useful, sigh. */
3647 1.1 brezak error = 0;
3648 1.1 brezak }
3649 1.1 brezak break;
3650 1.1 brezak
3651 1.1 brezak default:
3652 1.1 brezak return ENXIO;
3653 1.87 kent /*NOTREACHED*/
3654 1.1 brezak }
3655 1.1 brezak return error;
3656 1.36 augustss }
3657 1.36 augustss
3658 1.36 augustss STATIC int
3659 1.87 kent gus_get_props(void *addr)
3660 1.36 augustss {
3661 1.87 kent struct gus_softc *sc;
3662 1.87 kent
3663 1.87 kent sc = addr;
3664 1.87 kent return AUDIO_PROP_MMAP |
3665 1.87 kent (sc->sc_recdrq == sc->sc_playdrq ? 0 : AUDIO_PROP_FULLDUPLEX);
3666 1.36 augustss }
3667 1.36 augustss
3668 1.36 augustss STATIC int
3669 1.87 kent gusmax_get_props(void *addr)
3670 1.36 augustss {
3671 1.87 kent struct ad1848_isa_softc *ac;
3672 1.87 kent
3673 1.87 kent ac = addr;
3674 1.62 jtk return gus_get_props(ac->sc_ad1848.parent);
3675 1.1 brezak }
3676 1.1 brezak
3677 1.8 jtk STATIC int
3678 1.96 christos gusmax_mixer_query_devinfo(void *addr, mixer_devinfo_t *dip)
3679 1.1 brezak {
3680 1.87 kent
3681 1.1 brezak DPRINTF(("gusmax_query_devinfo: index=%d\n", dip->index));
3682 1.1 brezak
3683 1.1 brezak switch(dip->index) {
3684 1.1 brezak #if 0
3685 1.87 kent case GUSMAX_MIC_IN_LVL: /* Microphone */
3686 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3687 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3688 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3689 1.87 kent dip->next = GUSMAX_MIC_IN_MUTE;
3690 1.87 kent strcpy(dip->label.name, AudioNmicrophone);
3691 1.87 kent dip->un.v.num_channels = 2;
3692 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3693 1.87 kent break;
3694 1.1 brezak #endif
3695 1.1 brezak
3696 1.87 kent case GUSMAX_MONO_LVL: /* mono/microphone mixer */
3697 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3698 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3699 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3700 1.87 kent dip->next = GUSMAX_MONO_MUTE;
3701 1.87 kent strcpy(dip->label.name, AudioNmicrophone);
3702 1.87 kent dip->un.v.num_channels = 1;
3703 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3704 1.87 kent break;
3705 1.87 kent
3706 1.87 kent case GUSMAX_DAC_LVL: /* dacout */
3707 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3708 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3709 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3710 1.87 kent dip->next = GUSMAX_DAC_MUTE;
3711 1.87 kent strcpy(dip->label.name, AudioNdac);
3712 1.87 kent dip->un.v.num_channels = 2;
3713 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3714 1.87 kent break;
3715 1.87 kent
3716 1.87 kent case GUSMAX_LINE_IN_LVL: /* line */
3717 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3718 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3719 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3720 1.87 kent dip->next = GUSMAX_LINE_IN_MUTE;
3721 1.87 kent strcpy(dip->label.name, AudioNline);
3722 1.87 kent dip->un.v.num_channels = 2;
3723 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3724 1.87 kent break;
3725 1.87 kent
3726 1.87 kent case GUSMAX_CD_LVL: /* cd */
3727 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3728 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3729 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3730 1.87 kent dip->next = GUSMAX_CD_MUTE;
3731 1.87 kent strcpy(dip->label.name, AudioNcd);
3732 1.87 kent dip->un.v.num_channels = 2;
3733 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3734 1.87 kent break;
3735 1.87 kent
3736 1.87 kent
3737 1.87 kent case GUSMAX_MONITOR_LVL: /* monitor level */
3738 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3739 1.87 kent dip->mixer_class = GUSMAX_MONITOR_CLASS;
3740 1.87 kent dip->next = GUSMAX_MONITOR_MUTE;
3741 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3742 1.87 kent strcpy(dip->label.name, AudioNmonitor);
3743 1.87 kent dip->un.v.num_channels = 1;
3744 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3745 1.87 kent break;
3746 1.87 kent
3747 1.87 kent case GUSMAX_OUT_LVL: /* cs4231 output volume: not useful? */
3748 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3749 1.87 kent dip->mixer_class = GUSMAX_MONITOR_CLASS;
3750 1.87 kent dip->prev = dip->next = AUDIO_MIXER_LAST;
3751 1.87 kent strcpy(dip->label.name, AudioNoutput);
3752 1.87 kent dip->un.v.num_channels = 2;
3753 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3754 1.87 kent break;
3755 1.87 kent
3756 1.87 kent case GUSMAX_SPEAKER_LVL: /* fake speaker volume */
3757 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3758 1.87 kent dip->mixer_class = GUSMAX_MONITOR_CLASS;
3759 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3760 1.87 kent dip->next = GUSMAX_SPEAKER_MUTE;
3761 1.87 kent strcpy(dip->label.name, AudioNmaster);
3762 1.87 kent dip->un.v.num_channels = 2;
3763 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3764 1.87 kent break;
3765 1.87 kent
3766 1.87 kent case GUSMAX_LINE_IN_MUTE:
3767 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3768 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3769 1.87 kent dip->prev = GUSMAX_LINE_IN_LVL;
3770 1.87 kent dip->next = AUDIO_MIXER_LAST;
3771 1.87 kent goto mute;
3772 1.87 kent
3773 1.87 kent case GUSMAX_DAC_MUTE:
3774 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3775 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3776 1.87 kent dip->prev = GUSMAX_DAC_LVL;
3777 1.87 kent dip->next = AUDIO_MIXER_LAST;
3778 1.87 kent goto mute;
3779 1.87 kent
3780 1.87 kent case GUSMAX_CD_MUTE:
3781 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3782 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3783 1.87 kent dip->prev = GUSMAX_CD_LVL;
3784 1.87 kent dip->next = AUDIO_MIXER_LAST;
3785 1.87 kent goto mute;
3786 1.87 kent
3787 1.87 kent case GUSMAX_MONO_MUTE:
3788 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3789 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3790 1.87 kent dip->prev = GUSMAX_MONO_LVL;
3791 1.87 kent dip->next = AUDIO_MIXER_LAST;
3792 1.87 kent goto mute;
3793 1.87 kent
3794 1.87 kent case GUSMAX_MONITOR_MUTE:
3795 1.87 kent dip->mixer_class = GUSMAX_OUTPUT_CLASS;
3796 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3797 1.87 kent dip->prev = GUSMAX_MONITOR_LVL;
3798 1.87 kent dip->next = AUDIO_MIXER_LAST;
3799 1.87 kent goto mute;
3800 1.87 kent
3801 1.87 kent case GUSMAX_SPEAKER_MUTE:
3802 1.87 kent dip->mixer_class = GUSMAX_OUTPUT_CLASS;
3803 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3804 1.87 kent dip->prev = GUSMAX_SPEAKER_LVL;
3805 1.87 kent dip->next = AUDIO_MIXER_LAST;
3806 1.87 kent mute:
3807 1.87 kent strcpy(dip->label.name, AudioNmute);
3808 1.87 kent dip->un.e.num_mem = 2;
3809 1.87 kent strcpy(dip->un.e.member[0].label.name, AudioNoff);
3810 1.87 kent dip->un.e.member[0].ord = 0;
3811 1.87 kent strcpy(dip->un.e.member[1].label.name, AudioNon);
3812 1.87 kent dip->un.e.member[1].ord = 1;
3813 1.87 kent break;
3814 1.87 kent
3815 1.87 kent case GUSMAX_REC_LVL: /* record level */
3816 1.87 kent dip->type = AUDIO_MIXER_VALUE;
3817 1.87 kent dip->mixer_class = GUSMAX_RECORD_CLASS;
3818 1.87 kent dip->prev = AUDIO_MIXER_LAST;
3819 1.87 kent dip->next = GUSMAX_RECORD_SOURCE;
3820 1.87 kent strcpy(dip->label.name, AudioNrecord);
3821 1.87 kent dip->un.v.num_channels = 2;
3822 1.87 kent strcpy(dip->un.v.units.name, AudioNvolume);
3823 1.87 kent break;
3824 1.87 kent
3825 1.87 kent case GUSMAX_RECORD_SOURCE:
3826 1.87 kent dip->mixer_class = GUSMAX_RECORD_CLASS;
3827 1.87 kent dip->type = AUDIO_MIXER_ENUM;
3828 1.87 kent dip->prev = GUSMAX_REC_LVL;
3829 1.87 kent dip->next = AUDIO_MIXER_LAST;
3830 1.87 kent strcpy(dip->label.name, AudioNsource);
3831 1.87 kent dip->un.e.num_mem = 4;
3832 1.87 kent strcpy(dip->un.e.member[0].label.name, AudioNoutput);
3833 1.87 kent dip->un.e.member[0].ord = DAC_IN_PORT;
3834 1.87 kent strcpy(dip->un.e.member[1].label.name, AudioNmicrophone);
3835 1.87 kent dip->un.e.member[1].ord = MIC_IN_PORT;
3836 1.87 kent strcpy(dip->un.e.member[2].label.name, AudioNdac);
3837 1.87 kent dip->un.e.member[2].ord = AUX1_IN_PORT;
3838 1.87 kent strcpy(dip->un.e.member[3].label.name, AudioNline);
3839 1.87 kent dip->un.e.member[3].ord = LINE_IN_PORT;
3840 1.87 kent break;
3841 1.87 kent
3842 1.87 kent case GUSMAX_INPUT_CLASS: /* input class descriptor */
3843 1.87 kent dip->type = AUDIO_MIXER_CLASS;
3844 1.87 kent dip->mixer_class = GUSMAX_INPUT_CLASS;
3845 1.87 kent dip->next = dip->prev = AUDIO_MIXER_LAST;
3846 1.87 kent strcpy(dip->label.name, AudioCinputs);
3847 1.87 kent break;
3848 1.87 kent
3849 1.87 kent case GUSMAX_OUTPUT_CLASS: /* output class descriptor */
3850 1.87 kent dip->type = AUDIO_MIXER_CLASS;
3851 1.87 kent dip->mixer_class = GUSMAX_OUTPUT_CLASS;
3852 1.87 kent dip->next = dip->prev = AUDIO_MIXER_LAST;
3853 1.87 kent strcpy(dip->label.name, AudioCoutputs);
3854 1.87 kent break;
3855 1.87 kent
3856 1.87 kent case GUSMAX_MONITOR_CLASS: /* monitor class descriptor */
3857 1.87 kent dip->type = AUDIO_MIXER_CLASS;
3858 1.87 kent dip->mixer_class = GUSMAX_MONITOR_CLASS;
3859 1.87 kent dip->next = dip->prev = AUDIO_MIXER_LAST;
3860 1.87 kent strcpy(dip->label.name, AudioCmonitor);
3861 1.87 kent break;
3862 1.87 kent
3863 1.87 kent case GUSMAX_RECORD_CLASS: /* record source class */
3864 1.87 kent dip->type = AUDIO_MIXER_CLASS;
3865 1.87 kent dip->mixer_class = GUSMAX_RECORD_CLASS;
3866 1.87 kent dip->next = dip->prev = AUDIO_MIXER_LAST;
3867 1.87 kent strcpy(dip->label.name, AudioCrecord);
3868 1.87 kent break;
3869 1.87 kent
3870 1.87 kent default:
3871 1.87 kent return ENXIO;
3872 1.87 kent /*NOTREACHED*/
3873 1.87 kent }
3874 1.87 kent DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
3875 1.1 brezak return 0;
3876 1.1 brezak }
3877 1.1 brezak
3878 1.8 jtk STATIC int
3879 1.87 kent gus_mixer_query_devinfo(void *addr, mixer_devinfo_t *dip)
3880 1.1 brezak {
3881 1.87 kent struct gus_softc *sc;
3882 1.1 brezak
3883 1.1 brezak DPRINTF(("gusmax_query_devinfo: index=%d\n", dip->index));
3884 1.87 kent sc = addr;
3885 1.1 brezak if (!HAS_MIXER(sc) && dip->index > GUSICS_MASTER_MUTE)
3886 1.1 brezak return ENXIO;
3887 1.1 brezak
3888 1.1 brezak switch(dip->index) {
3889 1.1 brezak
3890 1.1 brezak case GUSICS_MIC_IN_LVL: /* Microphone */
3891 1.1 brezak dip->type = AUDIO_MIXER_VALUE;
3892 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3893 1.1 brezak dip->prev = AUDIO_MIXER_LAST;
3894 1.1 brezak dip->next = GUSICS_MIC_IN_MUTE;
3895 1.1 brezak strcpy(dip->label.name, AudioNmicrophone);
3896 1.1 brezak dip->un.v.num_channels = 2;
3897 1.1 brezak strcpy(dip->un.v.units.name, AudioNvolume);
3898 1.1 brezak break;
3899 1.1 brezak
3900 1.1 brezak case GUSICS_LINE_IN_LVL: /* line */
3901 1.1 brezak dip->type = AUDIO_MIXER_VALUE;
3902 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3903 1.1 brezak dip->prev = AUDIO_MIXER_LAST;
3904 1.1 brezak dip->next = GUSICS_LINE_IN_MUTE;
3905 1.1 brezak strcpy(dip->label.name, AudioNline);
3906 1.1 brezak dip->un.v.num_channels = 2;
3907 1.1 brezak strcpy(dip->un.v.units.name, AudioNvolume);
3908 1.1 brezak break;
3909 1.1 brezak
3910 1.1 brezak case GUSICS_CD_LVL: /* cd */
3911 1.1 brezak dip->type = AUDIO_MIXER_VALUE;
3912 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3913 1.1 brezak dip->prev = AUDIO_MIXER_LAST;
3914 1.1 brezak dip->next = GUSICS_CD_MUTE;
3915 1.1 brezak strcpy(dip->label.name, AudioNcd);
3916 1.1 brezak dip->un.v.num_channels = 2;
3917 1.1 brezak strcpy(dip->un.v.units.name, AudioNvolume);
3918 1.1 brezak break;
3919 1.1 brezak
3920 1.1 brezak case GUSICS_DAC_LVL: /* dacout */
3921 1.1 brezak dip->type = AUDIO_MIXER_VALUE;
3922 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3923 1.1 brezak dip->prev = AUDIO_MIXER_LAST;
3924 1.1 brezak dip->next = GUSICS_DAC_MUTE;
3925 1.1 brezak strcpy(dip->label.name, AudioNdac);
3926 1.1 brezak dip->un.v.num_channels = 2;
3927 1.1 brezak strcpy(dip->un.v.units.name, AudioNvolume);
3928 1.1 brezak break;
3929 1.1 brezak
3930 1.1 brezak case GUSICS_MASTER_LVL: /* master output */
3931 1.1 brezak dip->type = AUDIO_MIXER_VALUE;
3932 1.1 brezak dip->mixer_class = GUSICS_OUTPUT_CLASS;
3933 1.1 brezak dip->prev = AUDIO_MIXER_LAST;
3934 1.1 brezak dip->next = GUSICS_MASTER_MUTE;
3935 1.48 augustss strcpy(dip->label.name, AudioNmaster);
3936 1.1 brezak dip->un.v.num_channels = 2;
3937 1.1 brezak strcpy(dip->un.v.units.name, AudioNvolume);
3938 1.1 brezak break;
3939 1.1 brezak
3940 1.1 brezak
3941 1.1 brezak case GUSICS_LINE_IN_MUTE:
3942 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3943 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3944 1.1 brezak dip->prev = GUSICS_LINE_IN_LVL;
3945 1.1 brezak dip->next = AUDIO_MIXER_LAST;
3946 1.1 brezak goto mute;
3947 1.87 kent
3948 1.1 brezak case GUSICS_DAC_MUTE:
3949 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3950 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3951 1.1 brezak dip->prev = GUSICS_DAC_LVL;
3952 1.1 brezak dip->next = AUDIO_MIXER_LAST;
3953 1.1 brezak goto mute;
3954 1.1 brezak
3955 1.1 brezak case GUSICS_CD_MUTE:
3956 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3957 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3958 1.1 brezak dip->prev = GUSICS_CD_LVL;
3959 1.1 brezak dip->next = AUDIO_MIXER_LAST;
3960 1.1 brezak goto mute;
3961 1.87 kent
3962 1.1 brezak case GUSICS_MIC_IN_MUTE:
3963 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3964 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3965 1.1 brezak dip->prev = GUSICS_MIC_IN_LVL;
3966 1.1 brezak dip->next = AUDIO_MIXER_LAST;
3967 1.1 brezak goto mute;
3968 1.1 brezak
3969 1.1 brezak case GUSICS_MASTER_MUTE:
3970 1.1 brezak dip->mixer_class = GUSICS_OUTPUT_CLASS;
3971 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3972 1.1 brezak dip->prev = GUSICS_MASTER_LVL;
3973 1.1 brezak dip->next = AUDIO_MIXER_LAST;
3974 1.1 brezak mute:
3975 1.1 brezak strcpy(dip->label.name, AudioNmute);
3976 1.1 brezak dip->un.e.num_mem = 2;
3977 1.1 brezak strcpy(dip->un.e.member[0].label.name, AudioNoff);
3978 1.1 brezak dip->un.e.member[0].ord = 0;
3979 1.1 brezak strcpy(dip->un.e.member[1].label.name, AudioNon);
3980 1.1 brezak dip->un.e.member[1].ord = 1;
3981 1.1 brezak break;
3982 1.87 kent
3983 1.1 brezak case GUSICS_RECORD_SOURCE:
3984 1.1 brezak dip->mixer_class = GUSICS_RECORD_CLASS;
3985 1.1 brezak dip->type = AUDIO_MIXER_ENUM;
3986 1.1 brezak dip->prev = dip->next = AUDIO_MIXER_LAST;
3987 1.1 brezak strcpy(dip->label.name, AudioNsource);
3988 1.1 brezak dip->un.e.num_mem = 1;
3989 1.1 brezak strcpy(dip->un.e.member[0].label.name, AudioNoutput);
3990 1.1 brezak dip->un.e.member[0].ord = GUSICS_MASTER_LVL;
3991 1.1 brezak break;
3992 1.1 brezak
3993 1.1 brezak case GUSICS_INPUT_CLASS:
3994 1.1 brezak dip->type = AUDIO_MIXER_CLASS;
3995 1.1 brezak dip->mixer_class = GUSICS_INPUT_CLASS;
3996 1.1 brezak dip->next = dip->prev = AUDIO_MIXER_LAST;
3997 1.46 mycroft strcpy(dip->label.name, AudioCinputs);
3998 1.1 brezak break;
3999 1.1 brezak
4000 1.1 brezak case GUSICS_OUTPUT_CLASS:
4001 1.1 brezak dip->type = AUDIO_MIXER_CLASS;
4002 1.1 brezak dip->mixer_class = GUSICS_OUTPUT_CLASS;
4003 1.1 brezak dip->next = dip->prev = AUDIO_MIXER_LAST;
4004 1.46 mycroft strcpy(dip->label.name, AudioCoutputs);
4005 1.1 brezak break;
4006 1.1 brezak
4007 1.1 brezak case GUSICS_RECORD_CLASS:
4008 1.1 brezak dip->type = AUDIO_MIXER_CLASS;
4009 1.1 brezak dip->mixer_class = GUSICS_RECORD_CLASS;
4010 1.1 brezak dip->next = dip->prev = AUDIO_MIXER_LAST;
4011 1.46 mycroft strcpy(dip->label.name, AudioCrecord);
4012 1.1 brezak break;
4013 1.1 brezak
4014 1.1 brezak default:
4015 1.1 brezak return ENXIO;
4016 1.87 kent /*NOTREACHED*/
4017 1.1 brezak }
4018 1.1 brezak DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
4019 1.1 brezak return 0;
4020 1.1 brezak }
4021 1.1 brezak
4022 1.8 jtk STATIC int
4023 1.96 christos gus_query_encoding(void *addr, struct audio_encoding *fp)
4024 1.1 brezak {
4025 1.87 kent
4026 1.1 brezak switch (fp->index) {
4027 1.1 brezak case 0:
4028 1.1 brezak strcpy(fp->name, AudioEmulaw);
4029 1.24 augustss fp->encoding = AUDIO_ENCODING_ULAW;
4030 1.24 augustss fp->precision = 8;
4031 1.26 jtk fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
4032 1.1 brezak break;
4033 1.1 brezak case 1:
4034 1.47 mycroft strcpy(fp->name, AudioEslinear);
4035 1.32 augustss fp->encoding = AUDIO_ENCODING_SLINEAR;
4036 1.24 augustss fp->precision = 8;
4037 1.24 augustss fp->flags = 0;
4038 1.1 brezak break;
4039 1.1 brezak case 2:
4040 1.47 mycroft strcpy(fp->name, AudioEslinear_le);
4041 1.32 augustss fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
4042 1.24 augustss fp->precision = 16;
4043 1.24 augustss fp->flags = 0;
4044 1.24 augustss break;
4045 1.24 augustss case 3:
4046 1.26 jtk strcpy(fp->name, AudioEulinear);
4047 1.26 jtk fp->encoding = AUDIO_ENCODING_ULINEAR;
4048 1.24 augustss fp->precision = 8;
4049 1.24 augustss fp->flags = 0;
4050 1.24 augustss break;
4051 1.24 augustss case 4:
4052 1.24 augustss strcpy(fp->name, AudioEulinear_le);
4053 1.24 augustss fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
4054 1.24 augustss fp->precision = 16;
4055 1.24 augustss fp->flags = 0;
4056 1.29 jtk break;
4057 1.29 jtk case 5:
4058 1.47 mycroft strcpy(fp->name, AudioEslinear_be);
4059 1.32 augustss fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
4060 1.29 jtk fp->precision = 16;
4061 1.29 jtk fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
4062 1.29 jtk break;
4063 1.29 jtk case 6:
4064 1.29 jtk strcpy(fp->name, AudioEulinear_be);
4065 1.29 jtk fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
4066 1.29 jtk fp->precision = 16;
4067 1.29 jtk fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
4068 1.1 brezak break;
4069 1.39 augustss case 7:
4070 1.39 augustss strcpy(fp->name, AudioEalaw);
4071 1.39 augustss fp->encoding = AUDIO_ENCODING_ALAW;
4072 1.39 augustss fp->precision = 8;
4073 1.39 augustss fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
4074 1.39 augustss break;
4075 1.39 augustss
4076 1.1 brezak default:
4077 1.87 kent return EINVAL;
4078 1.1 brezak /*NOTREACHED*/
4079 1.1 brezak }
4080 1.87 kent return 0;
4081 1.1 brezak }
4082 1.1 brezak
4083 1.1 brezak /*
4084 1.1 brezak * Setup the ICS mixer in "transparent" mode: reset everything to a sensible
4085 1.1 brezak * level. Levels as suggested by GUS SDK code.
4086 1.1 brezak */
4087 1.8 jtk STATIC void
4088 1.87 kent gus_init_ics2101(struct gus_softc *sc)
4089 1.1 brezak {
4090 1.87 kent struct ics2101_softc *ic;
4091 1.87 kent
4092 1.87 kent ic = &sc->sc_mixer;
4093 1.43 augustss sc->sc_mixer.sc_iot = sc->sc_iot;
4094 1.43 augustss sc->sc_mixer.sc_selio = GUS_MIXER_SELECT;
4095 1.43 augustss sc->sc_mixer.sc_selio_ioh = sc->sc_ioh3;
4096 1.43 augustss sc->sc_mixer.sc_dataio = GUS_MIXER_DATA;
4097 1.43 augustss sc->sc_mixer.sc_dataio_ioh = sc->sc_ioh2;
4098 1.1 brezak sc->sc_mixer.sc_flags = (sc->sc_revision == 5) ? ICS_FLIP : 0;
4099 1.1 brezak
4100 1.1 brezak ics2101_mix_attenuate(ic,
4101 1.1 brezak GUSMIX_CHAN_MIC,
4102 1.1 brezak ICSMIX_LEFT,
4103 1.1 brezak ICSMIX_MIN_ATTN);
4104 1.1 brezak ics2101_mix_attenuate(ic,
4105 1.1 brezak GUSMIX_CHAN_MIC,
4106 1.1 brezak ICSMIX_RIGHT,
4107 1.1 brezak ICSMIX_MIN_ATTN);
4108 1.1 brezak /*
4109 1.1 brezak * Start with microphone muted by the mixer...
4110 1.1 brezak */
4111 1.1 brezak gusics_mic_mute(ic, 1);
4112 1.1 brezak
4113 1.1 brezak /* ... and enabled by the GUS master mix control */
4114 1.1 brezak gus_mic_ctl(sc, SPKR_ON);
4115 1.1 brezak
4116 1.1 brezak ics2101_mix_attenuate(ic,
4117 1.1 brezak GUSMIX_CHAN_LINE,
4118 1.1 brezak ICSMIX_LEFT,
4119 1.1 brezak ICSMIX_MIN_ATTN);
4120 1.1 brezak ics2101_mix_attenuate(ic,
4121 1.1 brezak GUSMIX_CHAN_LINE,
4122 1.1 brezak ICSMIX_RIGHT,
4123 1.1 brezak ICSMIX_MIN_ATTN);
4124 1.1 brezak
4125 1.1 brezak ics2101_mix_attenuate(ic,
4126 1.1 brezak GUSMIX_CHAN_CD,
4127 1.1 brezak ICSMIX_LEFT,
4128 1.1 brezak ICSMIX_MIN_ATTN);
4129 1.1 brezak ics2101_mix_attenuate(ic,
4130 1.1 brezak GUSMIX_CHAN_CD,
4131 1.1 brezak ICSMIX_RIGHT,
4132 1.1 brezak ICSMIX_MIN_ATTN);
4133 1.1 brezak
4134 1.1 brezak ics2101_mix_attenuate(ic,
4135 1.1 brezak GUSMIX_CHAN_DAC,
4136 1.1 brezak ICSMIX_LEFT,
4137 1.1 brezak ICSMIX_MIN_ATTN);
4138 1.1 brezak ics2101_mix_attenuate(ic,
4139 1.1 brezak GUSMIX_CHAN_DAC,
4140 1.1 brezak ICSMIX_RIGHT,
4141 1.1 brezak ICSMIX_MIN_ATTN);
4142 1.1 brezak
4143 1.1 brezak ics2101_mix_attenuate(ic,
4144 1.1 brezak ICSMIX_CHAN_4,
4145 1.1 brezak ICSMIX_LEFT,
4146 1.1 brezak ICSMIX_MAX_ATTN);
4147 1.1 brezak ics2101_mix_attenuate(ic,
4148 1.1 brezak ICSMIX_CHAN_4,
4149 1.1 brezak ICSMIX_RIGHT,
4150 1.1 brezak ICSMIX_MAX_ATTN);
4151 1.1 brezak
4152 1.1 brezak ics2101_mix_attenuate(ic,
4153 1.1 brezak GUSMIX_CHAN_MASTER,
4154 1.1 brezak ICSMIX_LEFT,
4155 1.1 brezak ICSMIX_MIN_ATTN);
4156 1.1 brezak ics2101_mix_attenuate(ic,
4157 1.1 brezak GUSMIX_CHAN_MASTER,
4158 1.1 brezak ICSMIX_RIGHT,
4159 1.1 brezak ICSMIX_MIN_ATTN);
4160 1.1 brezak /* unmute other stuff: */
4161 1.1 brezak gusics_cd_mute(ic, 0);
4162 1.1 brezak gusics_dac_mute(ic, 0);
4163 1.1 brezak gusics_linein_mute(ic, 0);
4164 1.1 brezak return;
4165 1.1 brezak }
4166