xref: /illumos-gate/usr/src/uts/common/sys/audioio.h (revision 88447a05)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn  * Common Development and Distribution License (the "License").
69acbbeafSnn  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*88447a05SGarrett D'Amore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
239acbbeafSnn  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_AUDIOIO_H
277c478bd9Sstevel@tonic-gate #define	_SYS_AUDIOIO_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/types32.h>
317c478bd9Sstevel@tonic-gate #include <sys/time.h>
327c478bd9Sstevel@tonic-gate #include <sys/ioccom.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * These are the ioctl calls for all Solaris audio devices, including
367c478bd9Sstevel@tonic-gate  * the x86 and SPARCstation audio devices.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * You are encouraged to design your code in a modular fashion so that
397c478bd9Sstevel@tonic-gate  * future changes to the interface can be incorporated with little
407c478bd9Sstevel@tonic-gate  * trouble.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef __cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * This structure contains state information for audio device IO streams.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate struct audio_prinfo {
517c478bd9Sstevel@tonic-gate 	/*
527c478bd9Sstevel@tonic-gate 	 * The following values describe the audio data encoding.
537c478bd9Sstevel@tonic-gate 	 */
547c478bd9Sstevel@tonic-gate 	uint_t sample_rate;	/* samples per second */
557c478bd9Sstevel@tonic-gate 	uint_t channels;	/* number of interleaved channels */
567c478bd9Sstevel@tonic-gate 	uint_t precision;	/* bit-width of each sample */
577c478bd9Sstevel@tonic-gate 	uint_t encoding;	/* data encoding method */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	/*
607c478bd9Sstevel@tonic-gate 	 * The following values control audio device configuration
617c478bd9Sstevel@tonic-gate 	 */
627c478bd9Sstevel@tonic-gate 	uint_t gain;		/* gain level: 0 - 255 */
637c478bd9Sstevel@tonic-gate 	uint_t port;		/* selected I/O port (see below) */
647c478bd9Sstevel@tonic-gate 	uint_t avail_ports;	/* available I/O ports (see below) */
657c478bd9Sstevel@tonic-gate 	uint_t mod_ports;	/* I/O ports that are modifiable (see below) */
667c478bd9Sstevel@tonic-gate 	uint_t _xxx;		/* Reserved for future use */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	uint_t buffer_size;	/* I/O buffer size */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	/*
717c478bd9Sstevel@tonic-gate 	 * The following values describe driver state
727c478bd9Sstevel@tonic-gate 	 */
737c478bd9Sstevel@tonic-gate 	uint_t samples;		/* number of samples converted */
747c478bd9Sstevel@tonic-gate 	uint_t eof;		/* End Of File counter (play only) */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	uchar_t	pause;		/* non-zero for pause, zero to resume */
777c478bd9Sstevel@tonic-gate 	uchar_t	error;		/* non-zero if overflow/underflow */
787c478bd9Sstevel@tonic-gate 	uchar_t	waiting;	/* non-zero if a process wants access */
797c478bd9Sstevel@tonic-gate 	uchar_t balance;	/* stereo channel balance */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	ushort_t minordev;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/*
847c478bd9Sstevel@tonic-gate 	 * The following values are read-only state flags
857c478bd9Sstevel@tonic-gate 	 */
867c478bd9Sstevel@tonic-gate 	uchar_t open;		/* non-zero if open access permitted */
877c478bd9Sstevel@tonic-gate 	uchar_t active;		/* non-zero if I/O is active */
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate typedef struct audio_prinfo audio_prinfo_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * This structure describes the current state of the audio device.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate struct audio_info {
967c478bd9Sstevel@tonic-gate 	/*
977c478bd9Sstevel@tonic-gate 	 * Per-stream information
987c478bd9Sstevel@tonic-gate 	 */
997c478bd9Sstevel@tonic-gate 	audio_prinfo_t play;	/* output status information */
1007c478bd9Sstevel@tonic-gate 	audio_prinfo_t record;	/* input status information */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/*
1037c478bd9Sstevel@tonic-gate 	 * Per-unit/channel information
1047c478bd9Sstevel@tonic-gate 	 */
1057c478bd9Sstevel@tonic-gate 	uint_t monitor_gain;	/* input to output mix: 0 - 255 */
1067c478bd9Sstevel@tonic-gate 	uchar_t output_muted;	/* non-zero if output is muted */
1077c478bd9Sstevel@tonic-gate 	uchar_t ref_cnt;	/* driver reference count, read only */
1087c478bd9Sstevel@tonic-gate 	uchar_t _xxx[2];	/* Reserved for future use */
1097c478bd9Sstevel@tonic-gate 	uint_t hw_features;	/* hardware features this driver supports */
1107c478bd9Sstevel@tonic-gate 	uint_t sw_features;	/* supported SW features */
1117c478bd9Sstevel@tonic-gate 	uint_t sw_features_enabled;	/* supported SW feat. enabled */
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate typedef struct audio_info audio_info_t;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Audio encoding types
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_NONE	(0)	/* no encoding assigned	*/
1207c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_ULAW	(1)	/* u-law encoding	*/
1217c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_ALAW	(2)	/* A-law encoding	*/
1227c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_LINEAR	(3)	/* Signed Linear PCM encoding	*/
1237c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_DVI	(104)	/* DVI ADPCM		*/
1247c478bd9Sstevel@tonic-gate #define	AUDIO_ENCODING_LINEAR8	(105)	/* 8 bit UNSIGNED	*/
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * These ranges apply to record, play, and monitor gain values
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate #define	AUDIO_MIN_GAIN	(0)	/* minimum gain value */
1307c478bd9Sstevel@tonic-gate #define	AUDIO_MAX_GAIN	(255)	/* maximum gain value */
1317c478bd9Sstevel@tonic-gate #define	AUDIO_MID_GAIN	(AUDIO_MAX_GAIN / 2)
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * These values apply to the balance field to adjust channel gain values
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate #define	AUDIO_LEFT_BALANCE	(0)	/* left channel only	*/
1377c478bd9Sstevel@tonic-gate #define	AUDIO_MID_BALANCE	(32)	/* equal left/right channel */
1387c478bd9Sstevel@tonic-gate #define	AUDIO_RIGHT_BALANCE	(64)	/* right channel only	*/
1397c478bd9Sstevel@tonic-gate #define	AUDIO_BALANCE_SHIFT	(3)
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Generic minimum/maximum limits for number of channels, both modes
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate #define	AUDIO_CHANNELS_MONO	(1)
1457c478bd9Sstevel@tonic-gate #define	AUDIO_CHANNELS_STEREO	(2)
1467c478bd9Sstevel@tonic-gate #define	AUDIO_MIN_PLAY_CHANNELS	(AUDIO_CHANNELS_MONO)
1477c478bd9Sstevel@tonic-gate #define	AUDIO_MAX_PLAY_CHANNELS	(AUDIO_CHANNELS_STEREO)
1487c478bd9Sstevel@tonic-gate #define	AUDIO_MIN_REC_CHANNELS	(AUDIO_CHANNELS_MONO)
1497c478bd9Sstevel@tonic-gate #define	AUDIO_MAX_REC_CHANNELS	(AUDIO_CHANNELS_STEREO)
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * Generic minimum/maximum limits for sample precision
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate #define	AUDIO_PRECISION_8		(8)
1557c478bd9Sstevel@tonic-gate #define	AUDIO_PRECISION_16		(16)
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define	AUDIO_MIN_PLAY_PRECISION	(8)
1587c478bd9Sstevel@tonic-gate #define	AUDIO_MAX_PLAY_PRECISION	(32)
1597c478bd9Sstevel@tonic-gate #define	AUDIO_MIN_REC_PRECISION		(8)
1607c478bd9Sstevel@tonic-gate #define	AUDIO_MAX_REC_PRECISION		(32)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * Define some convenient names for typical audio ports
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate #define	AUDIO_NONE		0x00	/* all ports off */
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * output ports (several may be enabled simultaneously)
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	AUDIO_SPEAKER		0x01	/* output to built-in speaker */
1707c478bd9Sstevel@tonic-gate #define	AUDIO_HEADPHONE		0x02	/* output to headphone jack */
1717c478bd9Sstevel@tonic-gate #define	AUDIO_LINE_OUT		0x04	/* output to line out	*/
1727c478bd9Sstevel@tonic-gate #define	AUDIO_SPDIF_OUT		0x08	/* output to SPDIF port	*/
1737c478bd9Sstevel@tonic-gate #define	AUDIO_AUX1_OUT		0x10	/* output to aux1 out	*/
1747c478bd9Sstevel@tonic-gate #define	AUDIO_AUX2_OUT		0x20	/* output to aux2 out	*/
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * input ports (usually only one at a time)
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate #define	AUDIO_MICROPHONE	0x01	/* input from microphone */
1807c478bd9Sstevel@tonic-gate #define	AUDIO_LINE_IN		0x02	/* input from line in	*/
1817c478bd9Sstevel@tonic-gate #define	AUDIO_CD		0x04	/* input from on-board CD inputs */
1827c478bd9Sstevel@tonic-gate #define	AUDIO_INTERNAL_CD_IN	AUDIO_CD	/* input from internal CDROM */
1837c478bd9Sstevel@tonic-gate #define	AUDIO_SPDIF_IN		0x08	/* input from SPDIF port */
1847c478bd9Sstevel@tonic-gate #define	AUDIO_AUX1_IN		0x10	/* input from aux1 in	*/
1857c478bd9Sstevel@tonic-gate #define	AUDIO_AUX2_IN		0x20	/* input from aux2 in	*/
1867c478bd9Sstevel@tonic-gate #define	AUDIO_CODEC_LOOPB_IN	0x40	/* input from Codec internal loopback */
1877c478bd9Sstevel@tonic-gate #define	AUDIO_SUNVTS		0x80	/* SunVTS input setting-internal LB */
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Define the hw_features
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate #define	AUDIO_HWFEATURE_DUPLEX	0x00000001u	/* simult. play & rec support */
1937c478bd9Sstevel@tonic-gate #define	AUDIO_HWFEATURE_MSCODEC	0x00000002u	/* multi-stream Codec */
1947c478bd9Sstevel@tonic-gate #define	AUDIO_HWFEATURE_IN2OUT	0x00000004u	/* input to output loopback */
1957c478bd9Sstevel@tonic-gate #define	AUDIO_HWFEATURE_PLAY	0x00000008u	/* device supports play */
1967c478bd9Sstevel@tonic-gate #define	AUDIO_HWFEATURE_RECORD	0x00000010u	/* device supports record */
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate  * Define the sw_features
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate #define	AUDIO_SWFEATURE_MIXER	0x00000001u	/* audio mixer audio pers mod */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * This macro initializes an audio_info structure to 'harmless' values.
2057c478bd9Sstevel@tonic-gate  * Note that (~0) might not be a harmless value for a flag that was
2067c478bd9Sstevel@tonic-gate  * a signed int.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #define	AUDIO_INITINFO(i)	{					\
2099acbbeafSnn 	uint_t	*__x__;							\
2109acbbeafSnn 	for (__x__ = (uint_t *)(i);					\
2117c478bd9Sstevel@tonic-gate 	    (char *)__x__ < (((char *)(i)) + sizeof (audio_info_t));	\
2129acbbeafSnn 	    *__x__++ = (uint_t)~0);					\
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate  * Parameter for the AUDIO_GETDEV ioctl to determine current
2187c478bd9Sstevel@tonic-gate  * audio devices.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate #define	MAX_AUDIO_DEV_LEN	(16)
2217c478bd9Sstevel@tonic-gate struct audio_device {
2227c478bd9Sstevel@tonic-gate 	char name[MAX_AUDIO_DEV_LEN];
2237c478bd9Sstevel@tonic-gate 	char version[MAX_AUDIO_DEV_LEN];
2247c478bd9Sstevel@tonic-gate 	char config[MAX_AUDIO_DEV_LEN];
2257c478bd9Sstevel@tonic-gate };
2267c478bd9Sstevel@tonic-gate typedef struct audio_device audio_device_t;
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * Ioctl calls for the audio device.
2317c478bd9Sstevel@tonic-gate  */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * AUDIO_GETINFO retrieves the current state of the audio device.
2357c478bd9Sstevel@tonic-gate  *
2367c478bd9Sstevel@tonic-gate  * AUDIO_SETINFO copies all fields of the audio_info structure whose
2377c478bd9Sstevel@tonic-gate  * values are not set to the initialized value (-1) to the device state.
2387c478bd9Sstevel@tonic-gate  * It performs an implicit AUDIO_GETINFO to return the new state of the
2397c478bd9Sstevel@tonic-gate  * device.  Note that the record.samples and play.samples fields are set
2407c478bd9Sstevel@tonic-gate  * to the last value before the AUDIO_SETINFO took effect.  This allows
2417c478bd9Sstevel@tonic-gate  * an application to reset the counters while atomically retrieving the
2427c478bd9Sstevel@tonic-gate  * last value.
2437c478bd9Sstevel@tonic-gate  *
2447c478bd9Sstevel@tonic-gate  * AUDIO_DRAIN suspends the calling process until the write buffers are
2457c478bd9Sstevel@tonic-gate  * empty.
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  * AUDIO_GETDEV returns a structure of type audio_device_t which contains
2487c478bd9Sstevel@tonic-gate  * three strings.  The string "name" is a short identifying string (for
2497c478bd9Sstevel@tonic-gate  * example, the SBus Fcode name string), the string "version" identifies
2507c478bd9Sstevel@tonic-gate  * the current version of the device, and the "config" string identifies
2517c478bd9Sstevel@tonic-gate  * the specific configuration of the audio stream.  All fields are
2527c478bd9Sstevel@tonic-gate  * device-dependent -- see the device specific manual pages for details.
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate #define	AUDIO_GETINFO	_IOR('A', 1, audio_info_t)
2557c478bd9Sstevel@tonic-gate #define	AUDIO_SETINFO	_IOWR('A', 2, audio_info_t)
2567c478bd9Sstevel@tonic-gate #define	AUDIO_DRAIN	_IO('A', 3)
2577c478bd9Sstevel@tonic-gate #define	AUDIO_GETDEV	_IOR('A', 4, audio_device_t)
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  * The following ioctl sets the audio device into an internal loopback mode,
2617c478bd9Sstevel@tonic-gate  * if the hardware supports this.  The argument is TRUE to set loopback,
2627c478bd9Sstevel@tonic-gate  * FALSE to reset to normal operation.  If the hardware does not support
2637c478bd9Sstevel@tonic-gate  * internal loopback, the ioctl should fail with EINVAL.
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate #define	AUDIO_DIAG_LOOPBACK	_IOW('A', 101, int)
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate #endif
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate #endif /* _SYS_AUDIOIO_H */
272