xref: /openbsd-src/sys/dev/audio_if.h (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*	$OpenBSD: audio_if.h,v 1.36 2019/09/05 05:33:57 ratchov 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 #include <sys/mutex.h>
42 
43 /*
44  * get_props
45  */
46 #define AUDIO_PROP_FULLDUPLEX	0x01
47 #define AUDIO_PROP_MMAP		0x02
48 #define AUDIO_PROP_INDEPENDENT	0x04
49 
50 #define AUDIO_BPS(bits)		(bits) <= 8 ? 1 : ((bits) <= 16 ? 2 : 4)
51 
52 /*
53  * Generic interface to hardware driver.
54  */
55 
56 struct mixer_devinfo;
57 struct mixer_ctrl;
58 
59 struct audio_params {
60 	u_long	sample_rate;			/* sample rate */
61 #define	AUDIO_ENCODING_NONE		0 /* no encoding assigned */
62 #define	AUDIO_ENCODING_ULAW		1 /* ITU G.711 mu-law */
63 #define	AUDIO_ENCODING_ALAW		2 /* ITU G.711 A-law */
64 #define AUDIO_ENCODING_SLINEAR_LE	6
65 #define AUDIO_ENCODING_SLINEAR_BE	7
66 #define AUDIO_ENCODING_ULINEAR_LE	8
67 #define AUDIO_ENCODING_ULINEAR_BE	9
68 	u_int	encoding;			/* mu-law, linear, etc */
69 	u_int	precision;			/* bits/sample */
70 	u_int	bps;				/* bytes/sample */
71 	u_int	msb;				/* data alignment */
72 	u_int	channels;			/* mono(1), stereo(2) */
73 };
74 
75 struct audio_hw_if {
76 	int	(*open)(void *, int);	/* open hardware */
77 	void	(*close)(void *);		/* close hardware */
78 
79 	/* Set the audio encoding parameters (record and play).
80 	 * Return 0 on success, or an error code if the
81 	 * requested parameters are impossible.
82 	 * The values in the params struct may be changed (e.g. rounding
83 	 * to the nearest sample rate.)
84 	 */
85 	int	(*set_params)(void *, int, int, struct audio_params *,
86 		    struct audio_params *);
87 
88 	/* Hardware may have some say in the blocksize to choose */
89 	int	(*round_blocksize)(void *, int);
90 
91 	/*
92 	 * Changing settings may require taking device out of "data mode",
93 	 * which can be quite expensive.  Also, audiosetinfo() may
94 	 * change several settings in quick succession.  To avoid
95 	 * having to take the device in/out of "data mode", we provide
96 	 * this function which indicates completion of settings
97 	 * adjustment.
98 	 */
99 	int	(*commit_settings)(void *);
100 
101 	/* Start input/output routines. These usually control DMA. */
102 	int	(*init_output)(void *, void *, int);
103 	int	(*init_input)(void *, void *, int);
104 	int	(*start_output)(void *, void *, int, void (*)(void *), void *);
105 	int	(*start_input)(void *, void *, int, void (*)(void *), void *);
106 	int	(*halt_output)(void *);
107 	int	(*halt_input)(void *);
108 
109 	int	(*speaker_ctl)(void *, int);
110 #define SPKR_ON		1
111 #define SPKR_OFF	0
112 
113 	int	(*setfd)(void *, int);
114 
115 	/* Mixer (in/out ports) */
116 	int	(*set_port)(void *, struct mixer_ctrl *);
117 	int	(*get_port)(void *, struct mixer_ctrl *);
118 
119 	int	(*query_devinfo)(void *, struct mixer_devinfo *);
120 
121 	/* Allocate/free memory for the ring buffer. Usually malloc/free. */
122 	/* The _old interfaces have been deprecated and will not be
123 	   called in newer kernels if the new interfaces are present */
124 	void	*(*allocm)(void *, int, size_t, int, int);
125 	void	(*freem)(void *, void *, int);
126 	size_t	(*round_buffersize)(void *, int, size_t);
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	(*copy_output)(void *, size_t);
135 	void	(*underrun)(void *);
136 	unsigned int (*set_blksz)(void *, int,
137 	    struct audio_params *, struct audio_params *, unsigned int);
138 	unsigned int (*set_nblks)(void *, int,
139 	    struct audio_params *, unsigned int, unsigned int);
140 };
141 
142 struct audio_attach_args {
143 	int	type;
144 	void	*hwif;		/* either audio_hw_if * or midi_hw_if * */
145 	void	*hdl;
146 };
147 #define	AUDIODEV_TYPE_AUDIO	0
148 #define	AUDIODEV_TYPE_MIDI	1
149 #define AUDIODEV_TYPE_OPL	2
150 #define AUDIODEV_TYPE_MPU	3
151 #define AUDIODEV_TYPE_RADIO	4
152 
153 /* Attach the MI driver(s) to the MD driver. */
154 struct device *audio_attach_mi(struct audio_hw_if *, void *, struct device *);
155 int	       audioprint(void *, const char *);
156 int	       audio_blksz_bytes(int,
157 		   struct audio_params *, struct audio_params *, int);
158 
159 extern struct mutex audio_lock;
160 
161 #endif /* _SYS_DEV_AUDIO_IF_H_ */
162