1 /* $OpenBSD: nec86hwvar.h,v 1.3 2016/09/19 06:46:43 ratchov Exp $ */ 2 /* $NecBSD: nec86hwvar.h,v 1.10 1998/03/14 07:04:55 kmatsuda Exp $ */ 3 /* $NetBSD$ */ 4 5 /* 6 * [NetBSD for NEC PC-98 series] 7 * Copyright (c) 1996, 1997, 1998 8 * NetBSD/pc98 porting staff. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * nec86hwvar.h 36 * 37 * NEC PC-9801-86 SoundBoard PCM driver for NetBSD/pc98. 38 * Written by NAGAO Tadaaki, Feb 10, 1996. 39 */ 40 41 #ifndef _NEC86HWVAR_H_ 42 #define _NEC86HWVAR_H_ 43 44 /* types of function which writes to/reads from FIFO buffer */ 45 struct nec86hw_softc; /* dummy declaration */ 46 typedef int (*func_fifo_output_t) (struct nec86hw_softc *, int); 47 typedef void (*func_fifo_input_t) (struct nec86hw_softc *, int); 48 49 50 struct nec86hw_softc { 51 struct device sc_dev; /* base device */ 52 53 bus_space_tag_t sc_iot; /* bus space tag */ 54 bus_space_handle_t sc_ioh; /* nec86 core chip space handle */ 55 56 u_int sc_cfgflags; /* config flags */ 57 #define NEC86HW_RATE_TYPE(flags) ((flags) & 1) 58 #define NEC86HW_NRATE_TYPE 2 59 60 u_short sc_open; /* reference count of open calls */ 61 62 u_long sc_irate; /* sample rate for input */ 63 u_long sc_orate; /* sample rate for output */ 64 65 u_long hw_irate; /* hardware rate for input */ 66 u_char hw_irate_bits; 67 u_long hw_orate; /* hardware rate for output */ 68 u_char hw_orate_bits; 69 70 u_int encoding; /* ulaw / linear */ 71 u_int precision; /* 8/16 bits */ 72 int channels; /* monoral(1) / stereo(2) */ 73 74 int in_port; /* Just keep track of it */ 75 #define NEC86HW_INPUT_MIXER 0 76 int out_port; /* Just keep track of it */ 77 #define NEC86HW_OUTPUT_MIXER 0 78 79 int model; /* board identification number */ 80 81 /* linear interpolation */ 82 u_long conv_acc; 83 u_short conv_last0; 84 u_short conv_last0_l; 85 u_short conv_last0_r; 86 u_short conv_last1; 87 u_short conv_last1_l; 88 u_short conv_last1_r; 89 90 void (*sc_intr)(void *); /* DMA completion intr handler */ 91 void *sc_arg; /* arg for sc_intr() */ 92 93 char intr_busy; /* whether the hardware running */ 94 95 /* pseudo-DMA */ 96 u_char *pdma_ptr; /* pointer to the data buffer */ 97 int pdma_count; /* size of the data in frames */ 98 int pdma_nchunk; /* number of chunks to do with */ 99 int pdma_watermark; /* interrupt trigger level */ 100 char pdma_padded; /* the buffer is padded out with 101 dummy zero's */ 102 char pdma_mode; /* input/output indicator */ 103 #define PDMA_MODE_NONE 0 104 #define PDMA_MODE_OUTPUT 1 105 #define PDMA_MODE_INPUT 2 106 107 /* function which writes to/reads from FIFO buffer */ 108 func_fifo_output_t func_fifo_output; 109 func_fifo_input_t func_fifo_input; 110 }; 111 112 struct nec86hw_functable_entry { 113 int precision; 114 int channels; 115 116 func_fifo_output_t func_fifo_output_direct; 117 func_fifo_input_t func_fifo_input_direct; 118 func_fifo_output_t func_fifo_output_resamp; 119 func_fifo_input_t func_fifo_input_resamp; 120 }; 121 122 /* 123 * Interrupt watermarks for the FIFO ring buffer on the hardware. 124 * 125 * These values must satisfy: 126 * 0 < WATERMARK_RATIO_OUT <= WATERMARK_MAX_RATIO 127 * 0 < WATERMARK_RATIO_IN <= WATERMARK_MAX_RATIO. 128 * (For more details, see also nec86hw_pdma_output() and nec86hw_pdma_input() 129 * in nec86hw.c) 130 */ 131 #define WATERMARK_MAX_RATIO 100 132 #define WATERMARK_RATIO_OUT 50 /* 50% of the blocksize */ 133 #define WATERMARK_RATIO_IN 50 /* 50% of NEC86_BUFFSIZE */ 134 135 /* 136 * Declarations of prototypes. 137 */ 138 #ifdef _KERNEL 139 void nec86hw_attach(struct nec86hw_softc *); 140 141 int nec86hw_open(void *, int); 142 void nec86hw_close(void *); 143 144 int nec86hw_set_params(void *, int, int, struct audio_params *, 145 struct audio_params *); 146 147 int nec86hw_round_blocksize(void *, int); 148 149 int nec86hw_set_out_port(void *, int); 150 int nec86hw_get_out_port(void *); 151 int nec86hw_set_in_port(void *, int); 152 int nec86hw_get_in_port(void *); 153 154 int nec86hw_commit_settings(void *); 155 156 int nec86hw_setfd(void *, int); 157 158 int nec86hw_mixer_set_port(void *, mixer_ctrl_t *); 159 int nec86hw_mixer_get_port(void *, mixer_ctrl_t *); 160 int nec86hw_mixer_query_devinfo(void *, mixer_devinfo_t *); 161 162 int nec86hw_pdma_init_output(void *, void *, int); 163 int nec86hw_pdma_init_input(void *, void *, int); 164 int nec86hw_pdma_output(void *, void *, int, void (*)(void *), void *); 165 int nec86hw_pdma_input(void *, void *, int, void (*)(void *), void *); 166 167 int nec86hw_speaker_ctl(void *, int); 168 169 int nec86hw_halt_pdma(void *); 170 int nec86hw_cont_pdma(void *); 171 172 u_char nec86hw_rate_bits(struct nec86hw_softc *, u_long); 173 int nec86hw_round_watermark(int); 174 175 int nec86hw_reset(struct nec86hw_softc *); 176 void nec86hw_set_mode_playing(struct nec86hw_softc *); 177 void nec86hw_set_mode_recording(struct nec86hw_softc *); 178 179 void nec86hw_set_volume(struct nec86hw_softc *, int, u_char); 180 181 void nec86hw_start_fifo(struct nec86hw_softc *); 182 void nec86hw_stop_fifo(struct nec86hw_softc *); 183 void nec86hw_enable_fifointr(struct nec86hw_softc *); 184 void nec86hw_disable_fifointr(struct nec86hw_softc *); 185 int nec86hw_seeif_intrflg(struct nec86hw_softc *); 186 void nec86hw_clear_intrflg(struct nec86hw_softc *); 187 void nec86hw_reset_fifo(struct nec86hw_softc *); 188 void nec86hw_set_watermark(struct nec86hw_softc *, int); 189 void nec86hw_set_precision_real(struct nec86hw_softc *, u_int); 190 void nec86hw_set_rate_real(struct nec86hw_softc *, u_char); 191 192 void nec86hw_output_chunk(struct nec86hw_softc *); 193 void nec86hw_input_chunk(struct nec86hw_softc *); 194 195 int nec86fifo_output_mono_8_direct(struct nec86hw_softc *, int); 196 int nec86fifo_output_mono_16_direct(struct nec86hw_softc *, int); 197 int nec86fifo_output_stereo_8_direct(struct nec86hw_softc *, int); 198 int nec86fifo_output_stereo_16_direct(struct nec86hw_softc *, int); 199 int nec86fifo_output_mono_8_resamp(struct nec86hw_softc *, int); 200 int nec86fifo_output_mono_16_resamp(struct nec86hw_softc *, int); 201 int nec86fifo_output_stereo_8_resamp(struct nec86hw_softc *, int); 202 int nec86fifo_output_stereo_16_resamp(struct nec86hw_softc *, int); 203 void nec86fifo_input_mono_8_direct(struct nec86hw_softc *, int); 204 void nec86fifo_input_mono_16_direct(struct nec86hw_softc *, int); 205 void nec86fifo_input_stereo_8_direct(struct nec86hw_softc *, int); 206 void nec86fifo_input_stereo_16_direct(struct nec86hw_softc *, int); 207 void nec86fifo_input_mono_8_resamp(struct nec86hw_softc *, int); 208 void nec86fifo_input_mono_16_resamp(struct nec86hw_softc *, int); 209 void nec86fifo_input_stereo_8_resamp(struct nec86hw_softc *, int); 210 void nec86fifo_input_stereo_16_resamp(struct nec86hw_softc *, int); 211 212 void nec86fifo_padding(struct nec86hw_softc *, int); 213 214 int nec86hw_intr(void *); 215 216 int nec86_get_props(void *); 217 218 #endif /* _KERNEL */ 219 #endif /* !_NEC86HWVAR_H_ */ 220