xref: /titanic_51/usr/src/uts/common/sys/audio/audio_common.h (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (C) 4Front Technologies 1996-2008.
23  *
24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_SYS_AUDIO_AUDIO_COMMON_H
29 #define	_SYS_AUDIO_AUDIO_COMMON_H
30 
31 #include <sys/mkdev.h>
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef	_KERNEL
39 
40 /* Shared data structures */
41 typedef struct audio_parms audio_parms_t;
42 typedef struct audio_buffer audio_buffer_t;
43 typedef struct audio_stream audio_stream_t;
44 typedef struct audio_engine audio_engine_t;
45 typedef struct audio_client audio_client_t;
46 typedef struct audio_dev audio_dev_t;
47 typedef struct audio_mixer_ops audio_mixer_ops_t;
48 typedef struct audio_engine_ops audio_engine_ops_t;
49 typedef struct audio_ctrl audio_ctrl_t;
50 typedef struct audio_ctrl_desc audio_ctrl_desc_t;
51 
52 struct audio_ctrl_desc {
53 	const char		*acd_name;		/* Controls Mnemonic */
54 	uint32_t		acd_type;		/* Entry type */
55 	uint64_t		acd_flags;		/* Characteristics */
56 	/*
57 	 * Minimum and Maximum values for this control.  The value
58 	 * must be between these values inclusive.  For
59 	 * AUDIO_CTRL_TYPE_ENUM, the maxvalue is a bitmask of
60 	 * supported controls.
61 	 */
62 	uint64_t		acd_maxvalue;		/* max value control */
63 	uint64_t		acd_minvalue;		/* min value control */
64 	/*
65 	 * Array of pointers to names for each enum position. This
66 	 * should be null for all but AUDIO_CTRL_TYPE_ENUM.
67 	 */
68 	const char		*acd_enum[64];
69 };
70 
71 /*
72  * Audio data formats.  Note that these are represented int a bit
73  * field, to allow for multiple values to be represented in the same
74  * integer (in certain portions of the API.)
75  */
76 #define	AUDIO_FORMAT_NONE		0x00000000U
77 #define	AUDIO_FORMAT_ULAW		0x00000001U
78 #define	AUDIO_FORMAT_ALAW		0x00000002U
79 #define	AUDIO_FORMAT_S8			0x00000004U
80 #define	AUDIO_FORMAT_U8			0x00000008U
81 #define	AUDIO_FORMAT_S16_LE		0x00000010U
82 #define	AUDIO_FORMAT_S16_BE		0x00000020U
83 #define	AUDIO_FORMAT_U16_LE		0x00000040U
84 #define	AUDIO_FORMAT_U16_BE		0x00000080U
85 #define	AUDIO_FORMAT_S24_LE		0x00000100U
86 #define	AUDIO_FORMAT_S24_BE		0x00000200U
87 #define	AUDIO_FORMAT_S32_LE		0x00000400U
88 #define	AUDIO_FORMAT_S32_BE		0x00000800U
89 #define	AUDIO_FORMAT_S24_PACKED		0x00001000U
90 #define	AUDIO_FORMAT_AC3		0x00010000U
91 #define	AUDIO_FORMAT_OPAQUE_MASK	0xffff0000U
92 #define	AUDIO_FORMAT_CONVERTIBLE	0x0000ffffU
93 /*
94  * We only support signed 16, 24, and 32 bit format conversions in the
95  * engines, for simplicity.  (We haven't run into any engines that
96  * require other formats.)
97  */
98 #define	AUDIO_FORMAT_PCM		0x00000f30
99 
100 /*
101  * Some big endian/little endian handling macros (native endian and opposite
102  * endian formats). The usage of these macros is described in the OSS
103  * Programmer's Manual.
104  */
105 
106 #if defined(_BIG_ENDIAN)
107 
108 #define	AUDIO_FORMAT_S16_NE	AUDIO_FORMAT_S16_BE
109 #define	AUDIO_FORMAT_U16_NE	AUDIO_FORMAT_U16_BE
110 #define	AUDIO_FORMAT_S32_NE	AUDIO_FORMAT_S32_BE
111 #define	AUDIO_FORMAT_S24_NE	AUDIO_FORMAT_S24_BE
112 #define	AUDIO_FORMAT_S16_OE	AUDIO_FORMAT_S16_LE
113 #define	AUDIO_FORMAT_U16_OE	AUDIO_FORMAT_U16_LE
114 #define	AUDIO_FORMAT_S32_OE	AUDIO_FORMAT_S32_LE
115 #define	AUDIO_FORMAT_S24_OE	AUDIO_FORMAT_S24_LE
116 
117 #elif defined(_LITTLE_ENDIAN)
118 #define	AUDIO_FORMAT_S16_NE	AUDIO_FORMAT_S16_LE
119 #define	AUDIO_FORMAT_U16_NE	AUDIO_FORMAT_U16_LE
120 #define	AUDIO_FORMAT_S32_NE	AUDIO_FORMAT_S32_LE
121 #define	AUDIO_FORMAT_S24_NE	AUDIO_FORMAT_S24_LE
122 #define	AUDIO_FORMAT_S16_OE	AUDIO_FORMAT_S16_BE
123 #define	AUDIO_FORMAT_U16_OE	AUDIO_FORMAT_U16_BE
124 #define	AUDIO_FORMAT_S32_OE	AUDIO_FORMAT_S32_BE
125 #define	AUDIO_FORMAT_S24_OE	AUDIO_FORMAT_S24_BE
126 
127 #else
128 #error "Machine endianness undefined"
129 #endif
130 
131 /*
132  * These are parameterized around the maximum minor number available
133  * for use in the filesystem.  Unfortunately, we have to use 32-bit limits,
134  * because we could have 32-bit userland apps (we usually will, in fact).
135  */
136 #define	AUDIO_MN_CLONE_NBITS	(NBITSMINOR32 - 1)
137 #define	AUDIO_MN_CLONE_MASK	(1U << (AUDIO_MN_CLONE_NBITS - 1))
138 #define	AUDIO_MN_TYPE_NBITS	(4)
139 #define	AUDIO_MN_TYPE_SHIFT	(0)
140 #define	AUDIO_MN_TYPE_MASK	((1U << AUDIO_MN_TYPE_NBITS) - 1)
141 #define	AUDIO_MN_INST_NBITS	((NBITSMINOR32 - 1) - AUDIO_MN_TYPE_NBITS)
142 #define	AUDIO_MN_INST_MASK	((1U << AUDIO_MN_INST_NBITS) - 1)
143 #define	AUDIO_MN_INST_SHIFT	(AUDIO_MN_TYPE_NBITS)
144 #define	AUDIO_MKMN(inst, typ)	\
145 	(((inst) << AUDIO_MN_INST_SHIFT) | ((typ) << AUDIO_MN_TYPE_SHIFT))
146 
147 #define	AUDIO_MINOR_MIXER	(0)
148 #define	AUDIO_MINOR_DSP		(1)
149 /* 2 is reserved for now */
150 #define	AUDIO_MINOR_DEVAUDIO	(3)
151 #define	AUDIO_MINOR_DEVAUDIOCTL	(4)
152 #define	AUDIO_MINOR_SNDSTAT	(AUDIO_MN_TYPE_MASK)
153 
154 /* reserved minors for driver specific use */
155 #define	AUDIO_MINOR_DRV1	(AUDIO_MINOR_SNDSTAT - 1)
156 #define	AUDIO_MINOR_DRV2	(AUDIO_MINOR_SNDSTAT - 2)
157 
158 
159 /* Various controls */
160 #define	AUDIO_CTRL_ID_VOLUME	"volume"
161 #define	AUDIO_CTRL_ID_LINEOUT	"line-out"
162 #define	AUDIO_CTRL_ID_FRONT	"front"
163 #define	AUDIO_CTRL_ID_REAR	"rear"
164 #define	AUDIO_CTRL_ID_HEADPHONE	"headphones"
165 #define	AUDIO_CTRL_ID_CENTER	"center"
166 #define	AUDIO_CTRL_ID_LFE	"lfe"
167 #define	AUDIO_CTRL_ID_SURROUND	"surround"
168 #define	AUDIO_CTRL_ID_SPEAKER	"speaker"
169 #define	AUDIO_CTRL_ID_AUX1OUT	"aux1-out"
170 #define	AUDIO_CTRL_ID_AUX2OUT	"aux2-out"
171 #define	AUDIO_CTRL_ID_BASS	"bass"
172 #define	AUDIO_CTRL_ID_TREBLE	"treble"
173 #define	AUDIO_CTRL_ID_3DDEPTH	"3d-depth"
174 #define	AUDIO_CTRL_ID_3DCENT	"3d-center"
175 #define	AUDIO_CTRL_ID_3DENHANCE	"3d-enhance"
176 #define	AUDIO_CTRL_ID_PHONE	"phone"
177 #define	AUDIO_CTRL_ID_MIC	"mic"
178 #define	AUDIO_CTRL_ID_LINEIN	"line-in"
179 #define	AUDIO_CTRL_ID_CD	"cd"
180 #define	AUDIO_CTRL_ID_VIDEO	"video"
181 #define	AUDIO_CTRL_ID_AUX1IN	"aux1-in"
182 #define	AUDIO_CTRL_ID_PCMIN	"pcm"
183 #define	AUDIO_CTRL_ID_RECGAIN	"record-gain"
184 #define	AUDIO_CTRL_ID_AUX2IN	"aux2-in"
185 #define	AUDIO_CTRL_ID_MICBOOST	"micboost"
186 #define	AUDIO_CTRL_ID_LOOPBACK	"loopback"
187 #define	AUDIO_CTRL_ID_LOUDNESS	"loudness"
188 #define	AUDIO_CTRL_ID_OUTPUTS	"outputs"
189 #define	AUDIO_CTRL_ID_INPUTS	"inputs"
190 #define	AUDIO_CTRL_ID_RECSRC	"record-source"
191 #define	AUDIO_CTRL_ID_MONSRC	"monitor-source"
192 #define	AUDIO_CTRL_ID_DIAG	"diag"
193 #define	AUDIO_CTRL_ID_BEEP	"beep"
194 #define	AUDIO_CTRL_ID_MONGAIN	"monitor-gain"
195 #define	AUDIO_CTRL_ID_STEREOSIM	"stereo-simulate"	/* AC'97 feature */
196 #define	AUDIO_CTRL_ID_MICGAIN	"mic-gain"		/* mono mic gain */
197 #define	AUDIO_CTRL_ID_SPKSRC	"speaker-source"	/* AC'97 feature */
198 #define	AUDIO_CTRL_ID_MICSRC	"mic-source"		/* AC'97 feature */
199 #define	AUDIO_CTRL_ID_JACK1	"jack1"			/* jack repurposing */
200 #define	AUDIO_CTRL_ID_JACK2	"jack2"
201 #define	AUDIO_CTRL_ID_JACK3	"jack3"
202 #define	AUDIO_CTRL_ID_JACK4	"jack4"
203 #define	AUDIO_CTRL_ID_JACK5	"jack5"
204 #define	AUDIO_CTRL_ID_JACK6	"jack6"
205 #define	AUDIO_CTRL_ID_JACK7	"jack7"
206 #define	AUDIO_CTRL_ID_DOWNMIX	"downmix"
207 #define	AUDIO_CTRL_ID_SPREAD	"spread"
208 
209 /*
210  * Names for ports.
211  */
212 #define	AUDIO_PORT_MIC			"mic"
213 #define	AUDIO_PORT_CD			"cd"
214 #define	AUDIO_PORT_VIDEO		"video"
215 #define	AUDIO_PORT_AUX1OUT		"aux1-out"
216 #define	AUDIO_PORT_AUX2OUT		"aux2-out"
217 #define	AUDIO_PORT_LINEOUT		"line-out"
218 #define	AUDIO_PORT_STEREOMIX		"stereo-mix"
219 #define	AUDIO_PORT_MONOMIX		"mono-mix"
220 #define	AUDIO_PORT_PHONE		"phone"
221 #define	AUDIO_PORT_REAR			"rear"
222 #define	AUDIO_PORT_CENTER		"center"
223 #define	AUDIO_PORT_SURROUND		"surround"
224 #define	AUDIO_PORT_LFE			"lfe"
225 #define	AUDIO_PORT_SPEAKER		"speaker"
226 #define	AUDIO_PORT_LINEIN		"line-in"
227 #define	AUDIO_PORT_AUX1IN		"aux1-in"
228 #define	AUDIO_PORT_AUX2IN		"aux2-in"
229 #define	AUDIO_PORT_HEADPHONES		"headphones"
230 #define	AUDIO_PORT_SPDIFIN		"spdif-in"
231 #define	AUDIO_PORT_SPDIFOUT		"spdif-out"
232 #define	AUDIO_PORT_CENLFE		"center/lfe"	/* combined jack use */
233 #define	AUDIO_PORT_MIC1			"mic1"
234 #define	AUDIO_PORT_MIC2			"mic2"
235 #define	AUDIO_PORT_DIGOUT		"digital-out"
236 #define	AUDIO_PORT_DIGIN		"digital-in"
237 #define	AUDIO_PORT_HDMI			"hdmi"
238 #define	AUDIO_PORT_MODEM		"modem"
239 #define	AUDIO_PORT_HANDSET		"handset"
240 #define	AUDIO_PORT_OTHER		"other"
241 #define	AUDIO_PORT_STEREO		"stereo"	/* e.g. mic array */
242 #define	AUDIO_PORT_NONE			"none"
243 
244 /*
245  * A few common values that sometimes we see.
246  */
247 #define	AUDIO_VALUE_ON			"on"
248 #define	AUDIO_VALUE_OFF			"off"
249 #define	AUDIO_VALUE_VERYLOW		"very-low"
250 #define	AUDIO_VALUE_LOW			"low"
251 #define	AUDIO_VALUE_MEDIUM		"medium"
252 #define	AUDIO_VALUE_HIGH		"high"
253 #define	AUDIO_VALUE_VERYHIGH		"very-high"
254 
255 /*
256  * Posible return values for walk callback function
257  */
258 #define	AUDIO_WALK_CONTINUE	1	/* continue walk */
259 #define	AUDIO_WALK_STOP		2	/* stop the walk */
260 #define	AUDIO_WALK_RESTART	3	/* restart the walk from beginning */
261 
262 /*
263  * Control types
264  */
265 #define	AUDIO_CTRL_TYPE_BOOLEAN		1	/* ON/OFF control */
266 #define	AUDIO_CTRL_TYPE_ENUM		2	/* Enumerated list */
267 #define	AUDIO_CTRL_TYPE_STEREO		3	/* stereo level control */
268 #define	AUDIO_CTRL_TYPE_MONO		4	/* mono level control */
269 #define	AUDIO_CTRL_TYPE_METER		5	/* VU meter */
270 
271 /*
272  * Control characteristics flags
273  */
274 #define	AUDIO_CTRL_FLAG_READABLE	0x00000001	/* Control readable */
275 #define	AUDIO_CTRL_FLAG_WRITEABLE	0x00000002	/* Control writable */
276 #define	AUDIO_CTRL_FLAG_RW		0x00000003	/* Read/writeable */
277 #define	AUDIO_CTRL_FLAG_VUPEAK		0x00000004	/* peak meter */
278 #define	AUDIO_CTRL_FLAG_CENTIBEL	0x00000008	/* Centibel (0.1 dB) */
279 #define	AUDIO_CTRL_FLAG_DECIBEL		0x00000010	/* Step size of 1 dB */
280 #define	AUDIO_CTRL_FLAG_POLL		0x00000020	/* May change itself */
281 #define	AUDIO_CTRL_FLAG_MAINVOL		0x00000100	/* Main volume ctrl */
282 #define	AUDIO_CTRL_FLAG_PCMVOL		0x00000200	/* PCM output volume */
283 #define	AUDIO_CTRL_FLAG_RECVOL		0x00000400	/* PCM record volume */
284 #define	AUDIO_CTRL_FLAG_MONVOL		0x00000800	/* Monitor volume */
285 #define	AUDIO_CTRL_FLAG_PLAY		0x00001000	/* Playback control */
286 #define	AUDIO_CTRL_FLAG_REC		0x00002000	/* Record control */
287 #define	AUDIO_CTRL_FLAG_3D		0x00004000	/* 3D effect control */
288 #define	AUDIO_CTRL_FLAG_TONE		0x00008000	/* Tone control */
289 #define	AUDIO_CTRL_FLAG_MONITOR		0x00010000	/* Monitor control */
290 #define	AUDIO_CTRL_FLAG_DIGITAL		0x00020000	/* Digital control */
291 
292 /*
293  * AUDIO_CTRL_TYPE_ENUM might allow more than a single value to be
294  * selected.  (Value is a bitmask.)
295  */
296 #define	AUDIO_CTRL_FLAG_MULTI		0x00000040
297 
298 #endif	/* _KERNEL */
299 
300 #ifdef	__cplusplus
301 }
302 #endif
303 
304 #endif	/* _SYS_AUDIO_AUDIO_COMMON_H */
305