1 /* $OpenBSD: emuxkivar.h,v 1.7 2005/11/30 22:17:47 brad Exp $ */
2 /* $NetBSD: emuxkivar.h,v 1.1 2001/10/17 18:39:41 jdolecek Exp $ */
3
4 /*-
5 * Copyright (c) 2001 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Yannick Montulet.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #ifndef _DEV_PCI_EMU10K1VAR_H_
41 #define _DEV_PCI_EMU10K1VAR_H_
42
43 #define EMU_PCI_CBIO 0x10
44 #define EMU_SUBSYS_APS 0x40011102
45
46 /*
47 * dma memory management
48 */
49
50 struct dmamem {
51 bus_dma_tag_t dmat;
52 bus_size_t size;
53 bus_size_t align;
54 bus_size_t bound;
55 bus_dma_segment_t *segs;
56 int nsegs;
57 int rsegs;
58 caddr_t kaddr;
59 bus_dmamap_t map;
60 };
61
62 #define KERNADDR(ptr) ((void *)((ptr)->kaddr))
63 #define DMASEGADDR(ptr, segno) ((ptr)->segs[segno].ds_addr)
64 #define DMAADDR(ptr) DMASEGADDR(ptr, 0)
65 #define DMASIZE(ptr) ((ptr)->size)
66
67 /*
68 * Emu10k1 hardware limits
69 */
70
71 #define EMU_PTESIZE 4096
72 #define EMU_MAXPTE ((EMU_CHAN_PSST_LOOPSTARTADDR_MASK + 1) / \
73 EMU_PTESIZE)
74 #define EMU_NUMCHAN 64
75 #define EMU_NUMRECSRCS 3
76
77 #define EMU_DMA_ALIGN 4096
78 #define EMU_DMAMEM_NSEG 1
79
80 /*
81 * Emu10k1 memory management
82 */
83
84 struct emuxki_mem {
85 LIST_ENTRY(emuxki_mem) next;
86 struct dmamem *dmamem;
87 u_int16_t ptbidx;
88 #define EMU_RMEM 0xFFFF /* recording memory */
89 };
90
91 /*
92 * Emu10k1 play channel params
93 */
94
95 struct emuxki_chanparms_fxsend {
96 struct {
97 u_int8_t level, dest;
98 } a, b, c, d, e, f, g, h;
99 };
100
101 struct emuxki_chanparms_pitch {
102 u_int16_t initial;/* 4 bits of octave, 12 bits of fractional
103 * octave */
104 u_int16_t current;/* 0x4000 == unity pitch shift */
105 u_int16_t target; /* 0x4000 == unity pitch shift */
106 u_int8_t envelope_amount; /* Signed 2's complement, +/-
107 * one octave peak extremes */
108 };
109
110 struct emuxki_chanparms_envelope {
111 u_int16_t current_state; /* 0x8000-n == 666*n usec delay */
112 u_int8_t hold_time; /* 127-n == n*(volume ? 88.2 :
113 * 42)msec */
114 u_int8_t attack_time; /* 0 = infinite, 1 = (volume ? 11 :
115 * 10.9) msec, 0x7f = 5.5msec */
116 u_int8_t sustain_level; /* 127 = full, 0 = off, 0.75dB
117 * increments */
118 u_int8_t decay_time; /* 0 = 43.7msec, 1 = 21.8msec, 0x7f =
119 * 22msec */
120 };
121
122 struct emuxki_chanparms_volume {
123 u_int16_t current, target;
124 struct emuxki_chanparms_envelope envelope;
125 };
126
127 struct emuxki_chanparms_filter {
128 u_int16_t initial_cutoff_frequency;
129 /*
130 * 6 most significant bits are semitones, 2 least significant bits
131 * are fractions
132 */
133 u_int16_t current_cutoff_frequency;
134 u_int16_t target_cutoff_frequency;
135 u_int8_t lowpass_resonance_height;
136 u_int8_t interpolation_ROM; /* 1 = full band, 7 = low
137 * pass */
138 u_int8_t envelope_amount; /* Signed 2's complement, +/-
139 * six octaves peak extremes */
140 u_int8_t LFO_modulation_depth; /* Signed 2's complement, +/-
141 * three octave extremes */
142 };
143
144 struct emuxki_chanparms_loop {
145 u_int32_t start; /* index in the PTB (in samples) */
146 u_int32_t end; /* index in the PTB (in samples) */
147 };
148
149 struct emuxki_chanparms_modulation {
150 struct emuxki_chanparms_envelope envelope;
151 u_int16_t LFO_state; /* 0x8000-n = 666*n usec delay */
152 };
153
154 struct emuxki_chanparms_vibrato_LFO {
155 u_int16_t state; /* 0x8000-n == 666*n usec delay */
156 u_int8_t modulation_depth; /* Signed 2's complement, +/-
157 * one octave extremes */
158 u_int8_t vibrato_depth; /* Signed 2's complement, +/- one
159 * octave extremes */
160 u_int8_t frequency; /* 0.039Hz steps, maximum of 9.85 Hz */
161 };
162
163 struct emuxki_channel {
164 u_int8_t num; /* voice number */
165 struct emuxki_voice *voice;
166 struct emuxki_chanparms_fxsend fxsend;
167 struct emuxki_chanparms_pitch pitch;
168 u_int16_t initial_attenuation; /* 0.375dB steps */
169 struct emuxki_chanparms_volume volume;
170 struct emuxki_chanparms_filter filter;
171 struct emuxki_chanparms_loop loop;
172 struct emuxki_chanparms_modulation modulation;
173 struct emuxki_chanparms_vibrato_LFO vibrato_LFO;
174 u_int8_t tremolo_depth;
175 };
176
177 /*
178 * Voices, streams
179 */
180
181 typedef enum {
182 EMU_RECSRC_MIC = 0,
183 EMU_RECSRC_ADC,
184 EMU_RECSRC_FX,
185 EMU_RECSRC_NOTSET
186 } emuxki_recsrc_t;
187
188 struct emuxki_voice {
189 struct emuxki_softc *sc; /* our softc */
190
191 u_int8_t use;
192 #define EMU_VOICE_USE_PLAY (1 << 0)
193 u_int8_t state;
194 #define EMU_VOICE_STATE_STARTED (1 << 0)
195 u_int8_t stereo;
196 #define EMU_VOICE_STEREO_NOTSET 0xFF
197 u_int8_t b16;
198 u_int32_t sample_rate;
199 union {
200 struct emuxki_channel *chan[2];
201 emuxki_recsrc_t source;
202 } dataloc;
203 struct emuxki_mem *buffer;
204 u_int16_t blksize;/* in samples */
205 u_int16_t trigblk;/* blk on which to trigger inth */
206 u_int16_t blkmod; /* Modulo value to wrap trigblk */
207 u_int16_t timerate;
208 void (*inth) (void *);
209 void *inthparam;
210 LIST_ENTRY(emuxki_voice) next;
211 };
212
213 #if 0 /* Not yet */
214 /*
215 * I intend this to be able to manage things like AC-3
216 */
217 struct emuxki_stream {
218 struct emu10k1 *emu;
219 u_int8_t nmono;
220 u_int8_t nstereo;
221 struct emuxki_voice *mono;
222 struct emuxki_voice *stereo;
223 LIST_ENTRY(emuxki_stream) next;
224 };
225 #endif /* Not yet */
226
227 struct emuxki_softc {
228 struct device sc_dev;
229 struct audio_device sc_audv;
230 enum {
231 EMUXKI_SBLIVE = 0x00, EMUXKI_AUDIGY = 0x01, EMUXKI_AUDIGY2 = 0x02,
232 EMUXKI_LIVE_5_1 = 0x04, EMUXKI_APS = 0x08
233 } sc_type;
234
235 /* Autoconfig parameters */
236 bus_space_tag_t sc_iot;
237 bus_space_handle_t sc_ioh;
238 bus_addr_t sc_iob;
239 bus_size_t sc_ios;
240 pci_chipset_tag_t sc_pc; /* PCI tag */
241 bus_dma_tag_t sc_dmat;
242 void *sc_ih; /* interrupt handler */
243
244 /* EMU10k1 device structures */
245 LIST_HEAD(, emuxki_mem) mem;
246
247 struct dmamem *ptb;
248 struct dmamem *silentpage;
249
250 struct emuxki_channel *channel[EMU_NUMCHAN];
251 struct emuxki_voice *recsrc[EMU_NUMRECSRCS];
252
253 LIST_HEAD(, emuxki_voice) voices;
254 /* LIST_HEAD(, emuxki_stream) streams; */
255
256 u_int8_t timerstate;
257 #define EMU_TIMER_STATE_ENABLED 1
258
259 struct ac97_host_if hostif;
260 struct ac97_codec_if *codecif;
261 struct device *sc_audev;
262
263 struct emuxki_voice *pvoice, *rvoice, *lvoice;
264 };
265
266 #endif /* !_DEV_PCI_EMU10K1VAR_H_ */