xref: /titanic_50/usr/src/uts/common/sys/audioio.h (revision 0e42dee69ed771bf604dd1789fca9d77b5bbe302)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1995-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_AUDIOIO_H
28 #define	_SYS_AUDIOIO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/types32.h>
34 #include <sys/time.h>
35 #include <sys/ioccom.h>
36 
37 /*
38  * These are the ioctl calls for all Solaris audio devices, including
39  * the x86 and SPARCstation audio devices.
40  *
41  * You are encouraged to design your code in a modular fashion so that
42  * future changes to the interface can be incorporated with little
43  * trouble.
44  */
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * This structure contains state information for audio device IO streams.
52  */
53 struct audio_prinfo {
54 	/*
55 	 * The following values describe the audio data encoding.
56 	 */
57 	uint_t sample_rate;	/* samples per second */
58 	uint_t channels;	/* number of interleaved channels */
59 	uint_t precision;	/* bit-width of each sample */
60 	uint_t encoding;	/* data encoding method */
61 
62 	/*
63 	 * The following values control audio device configuration
64 	 */
65 	uint_t gain;		/* gain level: 0 - 255 */
66 	uint_t port;		/* selected I/O port (see below) */
67 	uint_t avail_ports;	/* available I/O ports (see below) */
68 	uint_t mod_ports;	/* I/O ports that are modifiable (see below) */
69 	uint_t _xxx;		/* Reserved for future use */
70 
71 	uint_t buffer_size;	/* I/O buffer size */
72 
73 	/*
74 	 * The following values describe driver state
75 	 */
76 	uint_t samples;		/* number of samples converted */
77 	uint_t eof;		/* End Of File counter (play only) */
78 
79 	uchar_t	pause;		/* non-zero for pause, zero to resume */
80 	uchar_t	error;		/* non-zero if overflow/underflow */
81 	uchar_t	waiting;	/* non-zero if a process wants access */
82 	uchar_t balance;	/* stereo channel balance */
83 
84 	ushort_t minordev;
85 
86 	/*
87 	 * The following values are read-only state flags
88 	 */
89 	uchar_t open;		/* non-zero if open access permitted */
90 	uchar_t active;		/* non-zero if I/O is active */
91 };
92 typedef struct audio_prinfo audio_prinfo_t;
93 
94 
95 /*
96  * This structure describes the current state of the audio device.
97  */
98 struct audio_info {
99 	/*
100 	 * Per-stream information
101 	 */
102 	audio_prinfo_t play;	/* output status information */
103 	audio_prinfo_t record;	/* input status information */
104 
105 	/*
106 	 * Per-unit/channel information
107 	 */
108 	uint_t monitor_gain;	/* input to output mix: 0 - 255 */
109 	uchar_t output_muted;	/* non-zero if output is muted */
110 	uchar_t ref_cnt;	/* driver reference count, read only */
111 	uchar_t _xxx[2];	/* Reserved for future use */
112 	uint_t hw_features;	/* hardware features this driver supports */
113 	uint_t sw_features;	/* supported SW features */
114 	uint_t sw_features_enabled;	/* supported SW feat. enabled */
115 };
116 typedef struct audio_info audio_info_t;
117 
118 
119 /*
120  * Audio encoding types
121  */
122 #define	AUDIO_ENCODING_NONE	(0)	/* no encoding assigned	*/
123 #define	AUDIO_ENCODING_ULAW	(1)	/* u-law encoding	*/
124 #define	AUDIO_ENCODING_ALAW	(2)	/* A-law encoding	*/
125 #define	AUDIO_ENCODING_LINEAR	(3)	/* Signed Linear PCM encoding	*/
126 #define	AUDIO_ENCODING_DVI	(104)	/* DVI ADPCM		*/
127 #define	AUDIO_ENCODING_LINEAR8	(105)	/* 8 bit UNSIGNED	*/
128 
129 /*
130  * These ranges apply to record, play, and monitor gain values
131  */
132 #define	AUDIO_MIN_GAIN	(0)	/* minimum gain value */
133 #define	AUDIO_MAX_GAIN	(255)	/* maximum gain value */
134 #define	AUDIO_MID_GAIN	(AUDIO_MAX_GAIN / 2)
135 
136 /*
137  * These values apply to the balance field to adjust channel gain values
138  */
139 #define	AUDIO_LEFT_BALANCE	(0)	/* left channel only	*/
140 #define	AUDIO_MID_BALANCE	(32)	/* equal left/right channel */
141 #define	AUDIO_RIGHT_BALANCE	(64)	/* right channel only	*/
142 #define	AUDIO_BALANCE_SHIFT	(3)
143 
144 /*
145  * Generic minimum/maximum limits for number of channels, both modes
146  */
147 #define	AUDIO_CHANNELS_MONO	(1)
148 #define	AUDIO_CHANNELS_STEREO	(2)
149 #define	AUDIO_MIN_PLAY_CHANNELS	(AUDIO_CHANNELS_MONO)
150 #define	AUDIO_MAX_PLAY_CHANNELS	(AUDIO_CHANNELS_STEREO)
151 #define	AUDIO_MIN_REC_CHANNELS	(AUDIO_CHANNELS_MONO)
152 #define	AUDIO_MAX_REC_CHANNELS	(AUDIO_CHANNELS_STEREO)
153 
154 /*
155  * Generic minimum/maximum limits for sample precision
156  */
157 #define	AUDIO_PRECISION_8		(8)
158 #define	AUDIO_PRECISION_16		(16)
159 
160 #define	AUDIO_MIN_PLAY_PRECISION	(8)
161 #define	AUDIO_MAX_PLAY_PRECISION	(32)
162 #define	AUDIO_MIN_REC_PRECISION		(8)
163 #define	AUDIO_MAX_REC_PRECISION		(32)
164 
165 /*
166  * Define some convenient names for typical audio ports
167  */
168 #define	AUDIO_NONE		0x00	/* all ports off */
169 /*
170  * output ports (several may be enabled simultaneously)
171  */
172 #define	AUDIO_SPEAKER		0x01	/* output to built-in speaker */
173 #define	AUDIO_HEADPHONE		0x02	/* output to headphone jack */
174 #define	AUDIO_LINE_OUT		0x04	/* output to line out	*/
175 #define	AUDIO_SPDIF_OUT		0x08	/* output to SPDIF port	*/
176 #define	AUDIO_AUX1_OUT		0x10	/* output to aux1 out	*/
177 #define	AUDIO_AUX2_OUT		0x20	/* output to aux2 out	*/
178 
179 /*
180  * input ports (usually only one at a time)
181  */
182 #define	AUDIO_MICROPHONE	0x01	/* input from microphone */
183 #define	AUDIO_LINE_IN		0x02	/* input from line in	*/
184 #define	AUDIO_CD		0x04	/* input from on-board CD inputs */
185 #define	AUDIO_INTERNAL_CD_IN	AUDIO_CD	/* input from internal CDROM */
186 #define	AUDIO_SPDIF_IN		0x08	/* input from SPDIF port */
187 #define	AUDIO_AUX1_IN		0x10	/* input from aux1 in	*/
188 #define	AUDIO_AUX2_IN		0x20	/* input from aux2 in	*/
189 #define	AUDIO_CODEC_LOOPB_IN	0x40	/* input from Codec internal loopback */
190 #define	AUDIO_SUNVTS		0x80	/* SunVTS input setting-internal LB */
191 
192 /*
193  * Define the hw_features
194  */
195 #define	AUDIO_HWFEATURE_DUPLEX	0x00000001u	/* simult. play & rec support */
196 #define	AUDIO_HWFEATURE_MSCODEC	0x00000002u	/* multi-stream Codec */
197 #define	AUDIO_HWFEATURE_IN2OUT	0x00000004u	/* input to output loopback */
198 #define	AUDIO_HWFEATURE_PLAY	0x00000008u	/* device supports play */
199 #define	AUDIO_HWFEATURE_RECORD	0x00000010u	/* device supports record */
200 
201 /*
202  * Define the sw_features
203  */
204 #define	AUDIO_SWFEATURE_MIXER	0x00000001u	/* audio mixer audio pers mod */
205 
206 /*
207  * This macro initializes an audio_info structure to 'harmless' values.
208  * Note that (~0) might not be a harmless value for a flag that was
209  * a signed int.
210  */
211 #define	AUDIO_INITINFO(i)	{					\
212 	uint_t	*__x__;						\
213 	for (__x__ = (uint_t *)(i);				\
214 	    (char *)__x__ < (((char *)(i)) + sizeof (audio_info_t));	\
215 	    *__x__++ = ~0);						\
216 }
217 
218 
219 /*
220  * Parameter for the AUDIO_GETDEV ioctl to determine current
221  * audio devices.
222  */
223 #define	MAX_AUDIO_DEV_LEN	(16)
224 struct audio_device {
225 	char name[MAX_AUDIO_DEV_LEN];
226 	char version[MAX_AUDIO_DEV_LEN];
227 	char config[MAX_AUDIO_DEV_LEN];
228 };
229 typedef struct audio_device audio_device_t;
230 
231 
232 /*
233  * Ioctl calls for the audio device.
234  */
235 
236 /*
237  * AUDIO_GETINFO retrieves the current state of the audio device.
238  *
239  * AUDIO_SETINFO copies all fields of the audio_info structure whose
240  * values are not set to the initialized value (-1) to the device state.
241  * It performs an implicit AUDIO_GETINFO to return the new state of the
242  * device.  Note that the record.samples and play.samples fields are set
243  * to the last value before the AUDIO_SETINFO took effect.  This allows
244  * an application to reset the counters while atomically retrieving the
245  * last value.
246  *
247  * AUDIO_DRAIN suspends the calling process until the write buffers are
248  * empty.
249  *
250  * AUDIO_GETDEV returns a structure of type audio_device_t which contains
251  * three strings.  The string "name" is a short identifying string (for
252  * example, the SBus Fcode name string), the string "version" identifies
253  * the current version of the device, and the "config" string identifies
254  * the specific configuration of the audio stream.  All fields are
255  * device-dependent -- see the device specific manual pages for details.
256  */
257 #define	AUDIO_GETINFO	_IOR('A', 1, audio_info_t)
258 #define	AUDIO_SETINFO	_IOWR('A', 2, audio_info_t)
259 #define	AUDIO_DRAIN	_IO('A', 3)
260 #define	AUDIO_GETDEV	_IOR('A', 4, audio_device_t)
261 
262 /*
263  * The following ioctl sets the audio device into an internal loopback mode,
264  * if the hardware supports this.  The argument is TRUE to set loopback,
265  * FALSE to reset to normal operation.  If the hardware does not support
266  * internal loopback, the ioctl should fail with EINVAL.
267  */
268 #define	AUDIO_DIAG_LOOPBACK	_IOW('A', 101, int)
269 
270 
271 /*
272  * Structure sent up as a M_PROTO message on trace streams
273  */
274 struct audtrace_hdr {
275 	uint_t seq;		/* Sequence number (per-aud_stream) */
276 	int type;		/* device-dependent */
277 #if defined(_LP64) || defined(_I32LPx)
278 	struct timeval32 timestamp;
279 #else
280 	struct timeval timestamp;
281 #endif
282 	char _f[8];		/* filler */
283 };
284 typedef struct audtrace_hdr audtrace_hdr_t;
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif /* _SYS_AUDIOIO_H */
291