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