xref: /openbsd-src/sys/dev/audio_if.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /*	$OpenBSD: audio_if.h,v 1.27 2010/07/15 03:43:11 jakemsr Exp $	*/
2 /*	$NetBSD: audio_if.h,v 1.24 1998/01/10 14:07:25 tv Exp $	*/
3 
4 /*
5  * Copyright (c) 1994 Havard Eidnes.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the Computer Systems
19  *	Engineering Group at Lawrence Berkeley Laboratory.
20  * 4. Neither the name of the University nor of the Laboratory may be used
21  *    to endorse or promote products derived from this software without
22  *    specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef _SYS_DEV_AUDIO_IF_H_
39 #define _SYS_DEV_AUDIO_IF_H_
40 
41 #define AUDIO_BPS(bits)		(bits) <= 8 ? 1 : ((bits) <= 16 ? 2 : 4)
42 
43 /*
44  * Generic interface to hardware driver.
45  */
46 
47 struct audio_softc;
48 struct audio_device;
49 struct audio_encoding;
50 struct mixer_devinfo;
51 struct mixer_ctrl;
52 
53 struct audio_params {
54 	u_long	sample_rate;			/* sample rate */
55 	u_int	encoding;			/* mu-law, linear, etc */
56 	u_int	precision;			/* bits/sample */
57 	u_int	bps;				/* bytes/sample */
58 	u_int	msb;				/* data alignment */
59 	u_int	channels;			/* mono(1), stereo(2) */
60 	/* Software en/decode functions, set if SW coding required by HW */
61 	void	(*sw_code)(void *, u_char *, int);
62 	int	factor;				/* coding space change */
63 };
64 
65 /* The default audio mode: 8 kHz mono mu-law */
66 extern struct audio_params audio_default;
67 
68 struct audio_hw_if {
69 	int	(*open)(void *, int);	/* open hardware */
70 	void	(*close)(void *);		/* close hardware */
71 	int	(*drain)(void *);		/* Optional: drain buffers */
72 
73 	/* Encoding. */
74 	/* XXX should we have separate in/out? */
75 	int	(*query_encoding)(void *, struct audio_encoding *);
76 
77 	/* Set the audio encoding parameters (record and play).
78 	 * Return 0 on success, or an error code if the
79 	 * requested parameters are impossible.
80 	 * The values in the params struct may be changed (e.g. rounding
81 	 * to the nearest sample rate.)
82 	 */
83 	int	(*set_params)(void *, int, int, struct audio_params *,
84 		    struct audio_params *);
85 
86 	/* Hardware may have some say in the blocksize to choose */
87 	int	(*round_blocksize)(void *, int);
88 
89 	/*
90 	 * Changing settings may require taking device out of "data mode",
91 	 * which can be quite expensive.  Also, audiosetinfo() may
92 	 * change several settings in quick succession.  To avoid
93 	 * having to take the device in/out of "data mode", we provide
94 	 * this function which indicates completion of settings
95 	 * adjustment.
96 	 */
97 	int	(*commit_settings)(void *);
98 
99 	/* Start input/output routines. These usually control DMA. */
100 	int	(*init_output)(void *, void *, int);
101 	int	(*init_input)(void *, void *, int);
102 	int	(*start_output)(void *, void *, int, void (*)(void *), void *);
103 	int	(*start_input)(void *, void *, int, void (*)(void *), void *);
104 	int	(*halt_output)(void *);
105 	int	(*halt_input)(void *);
106 
107 	int	(*speaker_ctl)(void *, int);
108 #define SPKR_ON		1
109 #define SPKR_OFF	0
110 
111 	int	(*getdev)(void *, struct audio_device *);
112 	int	(*setfd)(void *, int);
113 
114 	/* Mixer (in/out ports) */
115 	int	(*set_port)(void *, struct mixer_ctrl *);
116 	int	(*get_port)(void *, struct mixer_ctrl *);
117 
118 	int	(*query_devinfo)(void *, struct mixer_devinfo *);
119 
120 	/* Allocate/free memory for the ring buffer. Usually malloc/free. */
121 	/* The _old interfaces have been deprecated and will not be
122 	   called in newer kernels if the new interfaces are present */
123 	void	*(*allocm)(void *, int, size_t, int, int);
124 	void	(*freem)(void *, void *, int);
125 	size_t	(*round_buffersize)(void *, int, size_t);
126 	paddr_t	(*mappage)(void *, void *, off_t, int);
127 
128 	int	(*get_props)(void *); /* device properties */
129 
130 	int	(*trigger_output)(void *, void *, void *, int,
131 		    void (*)(void *), void *, struct audio_params *);
132 	int	(*trigger_input)(void *, void *, void *, int,
133 		    void (*)(void *), void *, struct audio_params *);
134 	void	(*get_default_params)(void *, int, struct audio_params *);
135 };
136 
137 struct audio_attach_args {
138 	int	type;
139 	void	*hwif;		/* either audio_hw_if * or midi_hw_if * */
140 	void	*hdl;
141 };
142 #define	AUDIODEV_TYPE_AUDIO	0
143 #define	AUDIODEV_TYPE_MIDI	1
144 #define AUDIODEV_TYPE_OPL	2
145 #define AUDIODEV_TYPE_MPU	3
146 #define AUDIODEV_TYPE_RADIO	4
147 
148 /* Attach the MI driver(s) to the MD driver. */
149 struct device *audio_attach_mi(struct audio_hw_if *, void *, struct device *);
150 int	       audioprint(void *, const char *);
151 
152 /* Device identity flags */
153 #define SOUND_DEVICE		0
154 #define AUDIO_DEVICE		0x80
155 #define AUDIOCTL_DEVICE		0xc0
156 #define MIXER_DEVICE		0x10
157 
158 #define AUDIOUNIT(x)		(minor(x)&0x0f)
159 #define AUDIODEV(x)		(minor(x)&0xf0)
160 
161 #define ISDEVSOUND(x)		(AUDIODEV((x)) == SOUND_DEVICE)
162 #define ISDEVAUDIO(x)		(AUDIODEV((x)) == AUDIO_DEVICE)
163 #define ISDEVAUDIOCTL(x)	(AUDIODEV((x)) == AUDIOCTL_DEVICE)
164 #define ISDEVMIXER(x)		(AUDIODEV((x)) == MIXER_DEVICE)
165 
166 /*
167  * USB Audio specification defines 12 channels:
168  *	L R C LFE Ls Rs Lc Rc S Sl Sr T
169  */
170 #define AUDIO_MAX_CHANNELS	12
171 
172 #endif /* _SYS_DEV_AUDIO_IF_H_ */
173 
174