sbdspvar.h revision 1.49
1/*	$NetBSD: sbdspvar.h,v 1.49 2000/06/26 04:56:22 simonb Exp $	*/
2
3/*
4 * Copyright (c) 1991-1993 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by the Computer Systems
18 *	Engineering Group at Lawrence Berkeley Laboratory.
19 * 4. Neither the name of the University nor of the Laboratory may be used
20 *    to endorse or promote products derived from this software without
21 *    specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#include "mpu.h"
38#if NMPU > 0
39#include <dev/ic/mpuvar.h>
40#endif
41
42#define SB_MASTER_VOL	0
43#define SB_MIDI_VOL	1
44#define SB_CD_VOL	2
45#define SB_VOICE_VOL	3
46#define SB_OUTPUT_CLASS	4
47
48#define SB_MIC_VOL	5
49#define SB_LINE_IN_VOL	6
50#define	SB_RECORD_SOURCE 7
51#define SB_TREBLE	8
52#define SB_BASS		9
53#define SB_RECORD_CLASS	10
54#define SB_INPUT_CLASS	11
55
56#define SB_PCSPEAKER	12
57#define SB_INPUT_GAIN	13
58#define SB_OUTPUT_GAIN	14
59#define SB_AGC		15
60#define SB_EQUALIZATION_CLASS 16
61
62#define SB_CD_IN_MUTE	17
63#define SB_MIC_IN_MUTE	18
64#define SB_LINE_IN_MUTE	19
65#define SB_MIDI_IN_MUTE	20
66
67#define SB_CD_SWAP	21
68#define SB_MIC_SWAP	22
69#define SB_LINE_SWAP	23
70#define SB_MIDI_SWAP	24
71
72#define SB_CD_OUT_MUTE	25
73#define SB_MIC_OUT_MUTE	26
74#define SB_LINE_OUT_MUTE 27
75
76#define SB_NDEVS	28
77
78#define SB_IS_IN_MUTE(x) ((x) < SB_CD_SWAP)
79
80/*
81 * Software state, per SoundBlaster card.
82 * The soundblaster has multiple functionality, which we must demultiplex.
83 * One approach is to have one major device number for the soundblaster card,
84 * and use different minor numbers to indicate which hardware function
85 * we want.  This would make for one large driver.  Instead our approach
86 * is to partition the design into a set of drivers that share an underlying
87 * piece of hardware.  Most things are hard to share, for example, the audio
88 * and midi ports.  For audio, we might want to mix two processes' signals,
89 * and for midi we might want to merge streams (this is hard due to
90 * running status).  Moreover, we should be able to re-use the high-level
91 * modules with other kinds of hardware.  In this module, we only handle the
92 * most basic communications with the sb card.
93 */
94struct sbdsp_softc {
95	struct	device sc_dev;		/* base device */
96	isa_chipset_tag_t sc_ic;
97	bus_space_tag_t sc_iot;		/* tag */
98	bus_space_handle_t sc_ioh;	/* handle */
99	void	*sc_ih;			/* interrupt vectoring */
100
101	/* XXX These are only for setting chip configuration registers. */
102	int	sc_iobase;		/* I/O port base address */
103	int	sc_irq;			/* interrupt */
104
105	int	sc_drq8;		/* DMA (8-bit) */
106	bus_size_t sc_drq8_maxsize;
107	int	sc_drq16;		/* DMA (16-bit) */
108	bus_size_t sc_drq16_maxsize;
109
110	int	sc_open;		/* reference count of open calls */
111#define SB_CLOSED 0
112#define SB_OPEN_AUDIO 1
113#define SB_OPEN_MIDI 2
114	int	sc_openflags;		/* flags used on open */
115	u_char	sc_fullduplex;		/* can do full duplex */
116
117	u_char	gain[SB_NDEVS][2];	/* kept in input levels */
118#define SB_LEFT 0
119#define SB_RIGHT 1
120#define SB_LR 0
121
122	u_int	in_mask;		/* input ports */
123	u_int	in_port;		/* XXX needed for MI interface */
124	u_int	in_filter;		/* one of SB_TREBLE_EQ, SB_BASS_EQ, 0 */
125
126	u_int	spkr_state;		/* non-null is on */
127
128	struct sbdsp_state {
129		u_int	rate;		/* Sample rate */
130		u_char	tc;		/* Time constant */
131		struct	sbmode *modep;
132		u_char	bmode;
133		int	dmachan;	/* DMA channel */
134		int	blksize;	/* Block size, preadjusted */
135		u_char	run;
136#define SB_NOTRUNNING 0		/* Not running, not initialized */
137#define SB_RUNNING 3		/* non-looping mode */
138#define SB_LOOPING 2		/* DMA&PCM running (looping mode) */
139	} sc_i, sc_o;			/* Input and output state */
140
141	u_long	sc_interrupts;		/* number of interrupts taken */
142
143	int	(*sc_intr8)(void*);	/* dma completion intr handler */
144	int	(*sc_intr16)(void*);	/* dma completion intr handler */
145	void	(*sc_intrp)(void*);	/* PCM output intr handler */
146	void	*sc_argp;		/* arg for sc_intrp() */
147	void	(*sc_intrr)(void*);	/* PCM input intr handler */
148	void	*sc_argr;		/* arg for sc_intrr() */
149	void	(*sc_intrm)(void*, int);/* midi input intr handler */
150	void	*sc_argm;		/* arg for sc_intrm() */
151
152	u_int	sc_mixer_model;
153#define SBM_NONE	0
154#define SBM_CT1335	1
155#define SBM_CT1345	2
156#define SBM_CT1XX5	3
157#define SBM_CT1745	4
158#define ISSBM1745(x) ((x)->sc_mixer_model >= SBM_CT1XX5)
159
160	u_int	sc_model;		/* DSP model */
161#define SB_UNK	-1
162#define SB_1	0			/* original SB */
163#define SB_20	1			/* SB 2 */
164#define SB_2x	2			/* SB 2, new version */
165#define SB_PRO	3			/* SB Pro */
166#define SB_JAZZ	4			/* Jazz 16 */
167#define SB_16	5			/* SB 16 */
168#define SB_32	6			/* SB AWE 32 */
169#define SB_64	7			/* SB AWE 64 */
170
171#define SB_NAMES { "SB_1", "SB_2.0", "SB_2.x", "SB_Pro", "Jazz_16", "SB_16", "SB_AWE_32", "SB_AWE_64" }
172
173	u_int	sc_version;		/* DSP version */
174#define SBVER_MAJOR(v)	(((v)>>8) & 0xff)
175#define SBVER_MINOR(v)	((v)&0xff)
176
177#if NMPU > 0
178	int	sc_hasmpu;
179	struct device *sc_mpudev;
180	bus_space_tag_t sc_mpu_iot;	/* tag */
181	bus_space_handle_t sc_mpu_ioh;	/* handle */
182#endif
183};
184
185#define ISSBPRO(sc) ((sc)->sc_model == SB_PRO || (sc)->sc_model == SB_JAZZ)
186#define ISSBPROCLASS(sc) ((sc)->sc_model >= SB_PRO)
187#define ISSB16CLASS(sc) ((sc)->sc_model >= SB_16)
188
189#ifdef _KERNEL
190int	sbdsp_open __P((void *, int));
191void	sbdsp_close __P((void *));
192
193int	sbdsp_probe __P((struct sbdsp_softc *));
194void	sbdsp_attach __P((struct sbdsp_softc *));
195
196int	sbdsp_set_in_gain __P((void *, u_int, u_char));
197int	sbdsp_set_in_gain_real __P((void *, u_int, u_char));
198int	sbdsp_get_in_gain __P((void *));
199int	sbdsp_set_out_gain __P((void *, u_int, u_char));
200int	sbdsp_set_out_gain_real __P((void *, u_int, u_char));
201int	sbdsp_get_out_gain __P((void *));
202int	sbdsp_set_monitor_gain __P((void *, u_int));
203int	sbdsp_get_monitor_gain __P((void *));
204int	sbdsp_query_encoding __P((void *, struct audio_encoding *));
205int	sbdsp_set_params __P((void *, int, int, struct audio_params *, struct audio_params *));
206int	sbdsp_round_blocksize __P((void *, int));
207int	sbdsp_get_avail_in_ports __P((void *));
208int	sbdsp_get_avail_out_ports __P((void *));
209int	sbdsp_speaker_ctl __P((void *, int));
210
211int	sbdsp_commit __P((void *));
212int	sbdsp_trigger_output __P((void *, void *, void *, int, void (*)(void *),
213	    void *, struct audio_params *));
214int	sbdsp_trigger_input __P((void *, void *, void *, int, void (*)(void *),
215	    void *, struct audio_params *));
216int	sbdsp_halt_output __P((void *));
217int	sbdsp_halt_input __P((void *));
218
219void	sbdsp_compress __P((int, u_char *, int));
220void	sbdsp_expand __P((int, u_char *, int));
221
222int	sbdsp_reset __P((struct sbdsp_softc *));
223void	sbdsp_spkron __P((struct sbdsp_softc *));
224void	sbdsp_spkroff __P((struct sbdsp_softc *));
225
226int	sbdsp_wdsp __P((struct sbdsp_softc *, int v));
227int	sbdsp_rdsp __P((struct sbdsp_softc *));
228
229int	sbdsp_intr __P((void *));
230
231int	sbdsp_set_sr __P((struct sbdsp_softc *, u_long *, int));
232
233void	sbdsp_mix_write __P((struct sbdsp_softc *, int, int));
234int	sbdsp_mix_read __P((struct sbdsp_softc *, int));
235
236int	sbdsp_mixer_set_port __P((void *, mixer_ctrl_t *));
237int	sbdsp_mixer_get_port __P((void *, mixer_ctrl_t *));
238int	sbdsp_mixer_query_devinfo __P((void *, mixer_devinfo_t *));
239
240void 	*sb_malloc __P((void *, int, size_t, int, int));
241void	sb_free __P((void *, void *, int));
242size_t	sb_round_buffersize __P((void *, int, size_t));
243paddr_t	sb_mappage __P((void *, void *, off_t, int));
244
245int	sbdsp_get_props __P((void *));
246
247
248int	sbdsp_midi_open __P((void *, int,
249			     void (*iintr)__P((void *, int)),
250			     void (*ointr)__P((void *)), void *arg));
251void	sbdsp_midi_close __P((void *));
252int	sbdsp_midi_output __P((void *, int));
253void	sbdsp_midi_getinfo __P((void *, struct midi_info *));
254#endif
255