Home | History | Annotate | Line # | Download | only in audio
audio_if.h revision 1.2.2.2
      1  1.2.2.2  christos /*	$NetBSD: audio_if.h,v 1.2.2.2 2019/06/10 22:07:06 christos Exp $	*/
      2  1.2.2.2  christos 
      3  1.2.2.2  christos /*
      4  1.2.2.2  christos  * Copyright (c) 1994 Havard Eidnes.
      5  1.2.2.2  christos  * All rights reserved.
      6  1.2.2.2  christos  *
      7  1.2.2.2  christos  * Redistribution and use in source and binary forms, with or without
      8  1.2.2.2  christos  * modification, are permitted provided that the following conditions
      9  1.2.2.2  christos  * are met:
     10  1.2.2.2  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.2.2.2  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.2.2.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.2.2  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.2.2  christos  *    documentation and/or other materials provided with the distribution.
     15  1.2.2.2  christos  * 3. All advertising materials mentioning features or use of this software
     16  1.2.2.2  christos  *    must display the following acknowledgement:
     17  1.2.2.2  christos  *	This product includes software developed by the Computer Systems
     18  1.2.2.2  christos  *	Engineering Group at Lawrence Berkeley Laboratory.
     19  1.2.2.2  christos  * 4. Neither the name of the University nor of the Laboratory may be used
     20  1.2.2.2  christos  *    to endorse or promote products derived from this software without
     21  1.2.2.2  christos  *    specific prior written permission.
     22  1.2.2.2  christos  *
     23  1.2.2.2  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.2.2.2  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.2.2.2  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.2.2.2  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.2.2.2  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.2.2.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.2.2.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.2.2.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.2.2.2  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.2.2.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.2.2.2  christos  * SUCH DAMAGE.
     34  1.2.2.2  christos  *
     35  1.2.2.2  christos  */
     36  1.2.2.2  christos 
     37  1.2.2.2  christos #ifndef _SYS_DEV_AUDIO_AUDIO_IF_H_
     38  1.2.2.2  christos #define _SYS_DEV_AUDIO_AUDIO_IF_H_
     39  1.2.2.2  christos 
     40  1.2.2.2  christos #include <sys/types.h>
     41  1.2.2.2  christos #include <sys/audioio.h>
     42  1.2.2.2  christos #include <sys/mutex.h>
     43  1.2.2.2  christos 
     44  1.2.2.2  christos /* check we have an audio(4) configured into kernel */
     45  1.2.2.2  christos #if defined(_KERNEL_OPT)
     46  1.2.2.2  christos #include "audio.h"
     47  1.2.2.2  christos 
     48  1.2.2.2  christos #if (NAUDIO == 0) && (NMIDI == 0) && (NMIDIBUS == 0)
     49  1.2.2.2  christos #error "No 'audio* at audiobus?' or 'midi* at midibus?' or similar configured"
     50  1.2.2.2  christos #endif
     51  1.2.2.2  christos 
     52  1.2.2.2  christos #endif /* _KERNEL_OPT */
     53  1.2.2.2  christos 
     54  1.2.2.2  christos /*
     55  1.2.2.2  christos  * Interfaces for hardware drivers and MI audio.
     56  1.2.2.2  christos  */
     57  1.2.2.2  christos 
     58  1.2.2.2  christos struct audio_softc;
     59  1.2.2.2  christos 
     60  1.2.2.2  christos /**
     61  1.2.2.2  christos  * audio stream format
     62  1.2.2.2  christos  */
     63  1.2.2.2  christos typedef struct audio_params {
     64  1.2.2.2  christos 	u_int	sample_rate;	/* sample rate */
     65  1.2.2.2  christos 	u_int	encoding;	/* e.g. mu-law, linear, etc */
     66  1.2.2.2  christos 	u_int	precision;	/* bits/subframe */
     67  1.2.2.2  christos 	u_int	validbits;	/* valid bits in a subframe */
     68  1.2.2.2  christos 	u_int	channels;	/* mono(1), stereo(2) */
     69  1.2.2.2  christos } audio_params_t;
     70  1.2.2.2  christos 
     71  1.2.2.2  christos #define	AUFMT_INVALIDATE(fmt)	(fmt)->mode |= 0x80000000
     72  1.2.2.2  christos #define	AUFMT_VALIDATE(fmt)	(fmt)->mode &= 0x7fffffff
     73  1.2.2.2  christos #define	AUFMT_IS_VALID(fmt)	(((fmt)->mode & 0x80000000) == 0)
     74  1.2.2.2  christos 
     75  1.2.2.2  christos #include <dev/audio/audiofil.h>
     76  1.2.2.2  christos 
     77  1.2.2.2  christos struct audio_hw_if {
     78  1.2.2.2  christos 	int	(*open)(void *, int);	/* open hardware */
     79  1.2.2.2  christos 	void	(*close)(void *);	/* close hardware */
     80  1.2.2.2  christos 
     81  1.2.2.2  christos 	int	(*query_format)(void *, audio_format_query_t *);
     82  1.2.2.2  christos 	int	(*set_format)(void *, int,
     83  1.2.2.2  christos 		    const audio_params_t *, const audio_params_t *,
     84  1.2.2.2  christos 		    audio_filter_reg_t *, audio_filter_reg_t *);
     85  1.2.2.2  christos 
     86  1.2.2.2  christos 	/* Hardware may have some say in the blocksize to choose */
     87  1.2.2.2  christos 	int	(*round_blocksize)(void *, int, int, const audio_params_t *);
     88  1.2.2.2  christos 
     89  1.2.2.2  christos 	/*
     90  1.2.2.2  christos 	 * Changing settings may require taking device out of "data mode",
     91  1.2.2.2  christos 	 * which can be quite expensive.  Also, audiosetinfo() may
     92  1.2.2.2  christos 	 * change several settings in quick succession.  To avoid
     93  1.2.2.2  christos 	 * having to take the device in/out of "data mode", we provide
     94  1.2.2.2  christos 	 * this function which indicates completion of settings
     95  1.2.2.2  christos 	 * adjustment.
     96  1.2.2.2  christos 	 */
     97  1.2.2.2  christos 	int	(*commit_settings)(void *);
     98  1.2.2.2  christos 
     99  1.2.2.2  christos 	/* Start input/output routines. These usually control DMA. */
    100  1.2.2.2  christos 	int	(*init_output)(void *, void *, int);
    101  1.2.2.2  christos 	int	(*init_input)(void *, void *, int);
    102  1.2.2.2  christos 	int	(*start_output)(void *, void *, int,
    103  1.2.2.2  christos 				    void (*)(void *), void *);
    104  1.2.2.2  christos 	int	(*start_input)(void *, void *, int,
    105  1.2.2.2  christos 				   void (*)(void *), void *);
    106  1.2.2.2  christos 	int	(*halt_output)(void *);
    107  1.2.2.2  christos 	int	(*halt_input)(void *);
    108  1.2.2.2  christos 
    109  1.2.2.2  christos 	int	(*speaker_ctl)(void *, int);
    110  1.2.2.2  christos #define SPKR_ON		1
    111  1.2.2.2  christos #define SPKR_OFF	0
    112  1.2.2.2  christos 
    113  1.2.2.2  christos 	int	(*getdev)(void *, struct audio_device *);
    114  1.2.2.2  christos 
    115  1.2.2.2  christos 	/* Mixer (in/out ports) */
    116  1.2.2.2  christos 	int	(*set_port)(void *, mixer_ctrl_t *);
    117  1.2.2.2  christos 	int	(*get_port)(void *, mixer_ctrl_t *);
    118  1.2.2.2  christos 
    119  1.2.2.2  christos 	int	(*query_devinfo)(void *, mixer_devinfo_t *);
    120  1.2.2.2  christos 
    121  1.2.2.2  christos 	/* Allocate/free memory for the ring buffer. Usually malloc/free. */
    122  1.2.2.2  christos 	void	*(*allocm)(void *, int, size_t);
    123  1.2.2.2  christos 	void	(*freem)(void *, void *, size_t);
    124  1.2.2.2  christos 	size_t	(*round_buffersize)(void *, int, size_t);
    125  1.2.2.2  christos 
    126  1.2.2.2  christos 	int	(*get_props)(void *); /* device properties */
    127  1.2.2.2  christos 
    128  1.2.2.2  christos 	int	(*trigger_output)(void *, void *, void *, int,
    129  1.2.2.2  christos 		    void (*)(void *), void *, const audio_params_t *);
    130  1.2.2.2  christos 	int	(*trigger_input)(void *, void *, void *, int,
    131  1.2.2.2  christos 		    void (*)(void *), void *, const audio_params_t *);
    132  1.2.2.2  christos 	int	(*dev_ioctl)(void *, u_long, void *, int, struct lwp *);
    133  1.2.2.2  christos 	void	(*get_locks)(void *, kmutex_t **, kmutex_t **);
    134  1.2.2.2  christos };
    135  1.2.2.2  christos 
    136  1.2.2.2  christos struct audio_attach_args {
    137  1.2.2.2  christos 	int	type;
    138  1.2.2.2  christos 	const void *hwif;	/* either audio_hw_if * or midi_hw_if * */
    139  1.2.2.2  christos 	void	*hdl;
    140  1.2.2.2  christos };
    141  1.2.2.2  christos #define	AUDIODEV_TYPE_AUDIO	0
    142  1.2.2.2  christos #define	AUDIODEV_TYPE_MIDI	1
    143  1.2.2.2  christos #define AUDIODEV_TYPE_OPL	2
    144  1.2.2.2  christos #define AUDIODEV_TYPE_MPU	3
    145  1.2.2.2  christos #define AUDIODEV_TYPE_AUX	4
    146  1.2.2.2  christos 
    147  1.2.2.2  christos /* Attach the MI driver(s) to the MD driver. */
    148  1.2.2.2  christos device_t audio_attach_mi(const struct audio_hw_if *, void *, device_t);
    149  1.2.2.2  christos int	audioprint(void *, const char *);
    150  1.2.2.2  christos 
    151  1.2.2.2  christos extern int audio_query_format(const struct audio_format *, int,
    152  1.2.2.2  christos 	audio_format_query_t *);
    153  1.2.2.2  christos extern int audio_indexof_format(const struct audio_format *, int, int,
    154  1.2.2.2  christos 	const audio_params_t *);
    155  1.2.2.2  christos extern const char *audio_encoding_name(int);
    156  1.2.2.2  christos 
    157  1.2.2.2  christos /* Device identity flags */
    158  1.2.2.2  christos #define SOUND_DEVICE		0
    159  1.2.2.2  christos #define AUDIO_DEVICE		0x80
    160  1.2.2.2  christos #define AUDIOCTL_DEVICE		0xc0
    161  1.2.2.2  christos #define MIXER_DEVICE		0x10
    162  1.2.2.2  christos 
    163  1.2.2.2  christos #define AUDIOUNIT(x)		(minor(x)&0x0f)
    164  1.2.2.2  christos #define AUDIODEV(x)		(minor(x)&0xf0)
    165  1.2.2.2  christos 
    166  1.2.2.2  christos #define ISDEVSOUND(x)		(AUDIODEV((x)) == SOUND_DEVICE)
    167  1.2.2.2  christos #define ISDEVAUDIO(x)		(AUDIODEV((x)) == AUDIO_DEVICE)
    168  1.2.2.2  christos #define ISDEVAUDIOCTL(x)	(AUDIODEV((x)) == AUDIOCTL_DEVICE)
    169  1.2.2.2  christos #define ISDEVMIXER(x)		(AUDIODEV((x)) == MIXER_DEVICE)
    170  1.2.2.2  christos 
    171  1.2.2.2  christos /*
    172  1.2.2.2  christos  * USB Audio specification defines 12 channels:
    173  1.2.2.2  christos  *	L R C LFE Ls Rs Lc Rc S Sl Sr T
    174  1.2.2.2  christos  */
    175  1.2.2.2  christos #define AUDIO_MAX_CHANNELS	12
    176  1.2.2.2  christos 
    177  1.2.2.2  christos #endif /* _SYS_DEV_AUDIO_AUDIO_IF_H_ */
    178  1.2.2.2  christos 
    179