1 /* $OpenBSD: audio_if.h,v 1.13 2001/10/31 11:00:24 art 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 /* 42 * Generic interface to hardware driver. 43 */ 44 45 struct audio_softc; 46 47 struct audio_params { 48 u_long sample_rate; /* sample rate */ 49 u_int encoding; /* e.g. ulaw, linear, etc */ 50 u_int precision; /* bits/sample */ 51 u_int channels; /* mono(1), stereo(2) */ 52 /* Software en/decode functions, set if SW coding required by HW */ 53 void (*sw_code)__P((void *, u_char *, int)); 54 int factor; /* coding space change */ 55 }; 56 57 /* The default audio mode: 8 kHz mono ulaw */ 58 extern struct audio_params audio_default; 59 60 struct audio_hw_if { 61 int (*open)__P((void *, int)); /* open hardware */ 62 void (*close)__P((void *)); /* close hardware */ 63 int (*drain)__P((void *)); /* Optional: drain buffers */ 64 65 /* Encoding. */ 66 /* XXX should we have separate in/out? */ 67 int (*query_encoding)__P((void *, struct audio_encoding *)); 68 69 /* Set the audio encoding parameters (record and play). 70 * Return 0 on success, or an error code if the 71 * requested parameters are impossible. 72 * The values in the params struct may be changed (e.g. rounding 73 * to the nearest sample rate.) 74 */ 75 int (*set_params)__P((void *, int, int, struct audio_params *, 76 struct audio_params *)); 77 78 /* Hardware may have some say in the blocksize to choose */ 79 int (*round_blocksize)__P((void *, int)); 80 81 /* 82 * Changing settings may require taking device out of "data mode", 83 * which can be quite expensive. Also, audiosetinfo() may 84 * change several settings in quick succession. To avoid 85 * having to take the device in/out of "data mode", we provide 86 * this function which indicates completion of settings 87 * adjustment. 88 */ 89 int (*commit_settings)__P((void *)); 90 91 /* Start input/output routines. These usually control DMA. */ 92 int (*init_output)__P((void *, void *, int)); 93 int (*init_input)__P((void *, void *, int)); 94 int (*start_output)__P((void *, void *, int, 95 void (*)(void *), void *)); 96 int (*start_input)__P((void *, void *, int, 97 void (*)(void *), void *)); 98 int (*halt_output)__P((void *)); 99 int (*halt_input)__P((void *)); 100 101 int (*speaker_ctl)__P((void *, int)); 102 #define SPKR_ON 1 103 #define SPKR_OFF 0 104 105 int (*getdev)__P((void *, struct audio_device *)); 106 int (*setfd)__P((void *, int)); 107 108 /* Mixer (in/out ports) */ 109 int (*set_port)__P((void *, mixer_ctrl_t *)); 110 int (*get_port)__P((void *, mixer_ctrl_t *)); 111 112 int (*query_devinfo)__P((void *, mixer_devinfo_t *)); 113 114 /* Allocate/free memory for the ring buffer. Usually malloc/free. */ 115 /* The _old interfaces have been deprecated and will not be 116 called in newer kernels if the new interfaces are present */ 117 void *(*allocm_old)__P((void *, unsigned long, int, int)); 118 void (*freem)__P((void *, void *, int)); 119 unsigned long (*round_buffersize_old)__P((void *, unsigned long)); 120 paddr_t (*mappage)__P((void *, void *, off_t, int)); 121 122 int (*get_props)__P((void *)); /* device properties */ 123 124 int (*trigger_output)__P((void *, void *, void *, int, 125 void (*)(void *), void *, struct audio_params *)); 126 int (*trigger_input)__P((void *, void *, void *, int, 127 void (*)(void *), void *, struct audio_params *)); 128 129 void *(*allocm)__P((void *, int, size_t, int, int)); 130 size_t (*round_buffersize)__P((void *, int, size_t)); 131 }; 132 133 struct audio_attach_args { 134 int type; 135 void *hwif; /* either audio_hw_if * or midi_hw_if * */ 136 void *hdl; 137 }; 138 #define AUDIODEV_TYPE_AUDIO 0 139 #define AUDIODEV_TYPE_MIDI 1 140 #define AUDIODEV_TYPE_OPL 2 141 #define AUDIODEV_TYPE_MPU 3 142 143 /* Attach the MI driver(s) to the MD driver. */ 144 struct device *audio_attach_mi __P((struct audio_hw_if *, void *, 145 struct device *)); 146 int audioprint __P((void *, const char *)); 147 148 /* Device identity flags */ 149 #define SOUND_DEVICE 0 150 #define AUDIO_DEVICE 0x80 151 #define AUDIOCTL_DEVICE 0xc0 152 #define MIXER_DEVICE 0x10 153 154 #define AUDIOUNIT(x) (minor(x)&0x0f) 155 #define AUDIODEV(x) (minor(x)&0xf0) 156 157 #define ISDEVSOUND(x) (AUDIODEV((x)) == SOUND_DEVICE) 158 #define ISDEVAUDIO(x) (AUDIODEV((x)) == AUDIO_DEVICE) 159 #define ISDEVAUDIOCTL(x) (AUDIODEV((x)) == AUDIOCTL_DEVICE) 160 #define ISDEVMIXER(x) (AUDIODEV((x)) == MIXER_DEVICE) 161 162 #if !defined(__i386__) && !defined(__sparc64__) 163 #define splaudio splbio /* XXX */ 164 #define IPL_AUDIO IPL_BIO /* XXX */ 165 #endif 166 167 #endif /* _SYS_DEV_AUDIO_IF_H_ */ 168 169