1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 struct gus_voice {
102
103
104
105
106
107 unsigned char voccntl;
108 unsigned char volcntl;
109 unsigned char pan_pos;
110 int rate;
111
112
113
114
115
116 u_long start_addr;
117 u_long end_addr;
118 u_long current_addr;
119
120
121
122
123
124
125
126
127 int start_volume;
128 int current_volume;
129 int end_volume;
130 };
131
132
133
134
135 struct gus_softc {
136 struct device sc_dev;
137 struct device *sc_isa;
138 void *sc_ih;
139 struct timeout sc_dma_tmo;
140 bus_space_tag_t sc_iot;
141 bus_space_handle_t sc_ioh1;
142 bus_space_handle_t sc_ioh2;
143 bus_space_handle_t sc_ioh3;
144 bus_space_handle_t sc_ioh4;
145
146 int sc_iobase;
147 int sc_irq;
148 int sc_drq;
149 int sc_recdrq;
150
151 int sc_flags;
152 #define GUS_MIXER_INSTALLED 0x01
153 #define GUS_LOCKED 0x02
154 #define GUS_CODEC_INSTALLED 0x04
155 #define GUS_PLAYING 0x08
156 #define GUS_DMAOUT_ACTIVE 0x10
157 #define GUS_DMAIN_ACTIVE 0x20
158 #define GUS_OPEN 0x100
159 int sc_dsize;
160 int sc_voices;
161 u_char sc_revision;
162 u_char sc_mixcontrol;
163
164 u_long sc_orate;
165 u_long sc_irate;
166
167 int sc_encoding;
168 int sc_precision;
169 int sc_channels;
170 int sc_blocksize;
171 int sc_chanblocksize;
172
173 short sc_nbufs;
174 short sc_bufcnt;
175 void *sc_deintr_buf;
176
177 int sc_ogain;
178 u_char sc_out_port;
179 u_char sc_in_port;
180
181 void (*sc_dmaoutintr)(void *);
182 void *sc_outarg;
183 u_char *sc_dmaoutaddr;
184 u_long sc_gusaddr;
185 int sc_dmaoutcnt;
186
187 void (*sc_dmainintr)(void *);
188 void *sc_inarg;
189 u_char *sc_dmainaddr;
190 int sc_dmaincnt;
191
192 struct stereo_dma_intr {
193 void (*intr)(void *);
194 void *arg;
195 u_char *buffer;
196 u_long dmabuf;
197 int size;
198 int flags;
199 } sc_stereo;
200
201
202
203
204
205 int sc_dmabuf;
206 int sc_playbuf;
207
208
209
210
211
212
213 struct gus_voice sc_voc[32];
214 union {
215 struct ics2101_softc sc_mixer_u;
216 struct ad1848_softc sc_codec_u;
217 } u;
218 #define sc_mixer u.sc_mixer_u
219 #define sc_codec u.sc_codec_u
220 };
221
222 struct ics2101_volume {
223 u_char left;
224 u_char right;
225 };
226
227 #define HAS_CODEC(sc) ((sc)->sc_flags & GUS_CODEC_INSTALLED)
228 #define HAS_MIXER(sc) ((sc)->sc_flags & GUS_MIXER_INSTALLED)
229
230
231
232
233
234
235 #define GUSICS_MIC_IN_MUTE 0
236 #define GUSICS_LINE_IN_MUTE 1
237 #define GUSICS_MASTER_MUTE 2
238 #define GUSICS_CD_MUTE 3
239 #define GUSICS_DAC_MUTE 4
240 #define GUSICS_MIC_IN_LVL 5
241 #define GUSICS_LINE_IN_LVL 6
242 #define GUSICS_CD_LVL 7
243 #define GUSICS_DAC_LVL 8
244 #define GUSICS_MASTER_LVL 9
245
246 #define GUSICS_RECORD_SOURCE 10
247
248
249 #define GUSICS_INPUT_CLASS 11
250 #define GUSICS_OUTPUT_CLASS 12
251 #define GUSICS_RECORD_CLASS 13
252
253
254
255
256 #define GUSMAX_MONO_LVL 0
257
258 #define GUSMAX_DAC_LVL 1
259 #define GUSMAX_LINE_IN_LVL 2
260 #define GUSMAX_CD_LVL 3
261 #define GUSMAX_MONITOR_LVL 4
262 #define GUSMAX_OUT_LVL 5
263 #define GUSMAX_SPEAKER_LVL 6
264 #define GUSMAX_LINE_IN_MUTE 7
265 #define GUSMAX_DAC_MUTE 8
266 #define GUSMAX_CD_MUTE 9
267 #define GUSMAX_MONO_MUTE 10
268 #define GUSMAX_MONITOR_MUTE 11
269 #define GUSMAX_SPEAKER_MUTE 12
270
271 #define GUSMAX_REC_LVL 13
272
273 #define GUSMAX_RECORD_SOURCE 14
274
275
276 #define GUSMAX_INPUT_CLASS 15
277 #define GUSMAX_RECORD_CLASS 16
278 #define GUSMAX_MONITOR_CLASS 17
279 #define GUSMAX_OUTPUT_CLASS 18
280
281 #ifdef AUDIO_DEBUG
282 #define GUSPLAYDEBUG
283 #define DPRINTF(x) if (gusdebug) printf x
284 #define DMAPRINTF(x) if (gusdmadebug) printf x
285 extern int gusdebug;
286 extern int gusdmadebug;
287 #else
288 #define DPRINTF(x)
289 #define DMAPRINTF(x)
290 #endif
291 extern int gus_dostereo;
292
293 #define NDMARECS 2048
294 #ifdef GUSPLAYDEBUG
295 extern int gusstats;
296 struct dma_record {
297 struct timeval tv;
298 u_long gusaddr;
299 caddr_t bsdaddr;
300 u_short count;
301 u_char channel;
302 u_char direction;
303 };
304
305 extern struct dma_record dmarecords[NDMARECS];
306
307 extern int dmarecord_index;
308 #endif
309
310
311
312
313
314 int gusopen(void *, int);
315 void gusclose(void *);
316 void gusmax_close(void *);
317 int gusintr(void *);
318 int gus_set_in_gain(caddr_t, u_int, u_char);
319 int gus_get_in_gain(caddr_t);
320 int gus_set_out_gain(caddr_t, u_int, u_char);
321 int gus_get_out_gain(caddr_t);
322 int gus_set_params(void *, int, int, struct audio_params *, struct audio_params *);
323 int gusmax_set_params(void *, int, int, struct audio_params *, struct audio_params *);
324 int gus_round_blocksize(void *, int);
325 int gus_commit_settings(void *);
326 int gus_dma_output(void *, void *, int, void (*)(void *), void *);
327 int gus_dma_input(void *, void *, int, void (*)(void *), void *);
328 int gus_halt_out_dma(void *);
329 int gus_halt_in_dma(void *);
330 int gus_speaker_ctl(void *, int);
331 int gusmaxopen(void *, int);
332 int gusmax_round_blocksize(void *, int);
333 int gusmax_commit_settings(void *);
334 int gusmax_dma_output(void *, void *, int, void (*)(void *), void *);
335 int gusmax_dma_input(void *, void *, int, void (*)(void *), void *);
336 int gusmax_halt_out_dma(void *);
337 int gusmax_halt_in_dma(void *);
338 int gusmax_speaker_ctl(void *, int);
339 int gus_getdev(void *, struct audio_device *);
340
341 void gus_deinterleave(struct gus_softc *, void *, int);
342
343 int gus_mic_ctl(void *, int);
344 int gus_linein_ctl(void *, int);
345 int gus_test_iobase(bus_space_tag_t, int);
346 void guspoke(bus_space_tag_t, bus_space_handle_t, long, u_char);
347 void gusdmaout(struct gus_softc *, int, u_long, caddr_t, int);
348 int gus_init_cs4231(struct gus_softc *);
349 void gus_init_ics2101(struct gus_softc *);
350
351 void gus_set_chan_addrs(struct gus_softc *);
352 void gusreset(struct gus_softc *, int);
353 void gus_set_voices(struct gus_softc *, int);
354 void gus_set_volume(struct gus_softc *, int, int);
355 void gus_set_samprate(struct gus_softc *, int, int);
356 void gus_set_recrate(struct gus_softc *, u_long);
357 void gus_start_voice(struct gus_softc *, int, int);
358 void gus_stop_voice(struct gus_softc *, int, int);
359 void gus_set_endaddr(struct gus_softc *, int, u_long);
360 #ifdef GUSPLAYDEBUG
361 void gus_set_curaddr(struct gus_softc *, int, u_long);
362 u_long gus_get_curaddr(struct gus_softc *, int);
363 #endif
364 int gus_dmaout_intr(struct gus_softc *);
365 void gus_dmaout_dointr(struct gus_softc *);
366 void gus_dmaout_timeout(void *);
367 int gus_dmain_intr(struct gus_softc *);
368 int gus_voice_intr(struct gus_softc *);
369 void gus_start_playing(struct gus_softc *, int);
370 int gus_continue_playing(struct gus_softc *, int);
371 u_char guspeek(bus_space_tag_t, bus_space_handle_t, u_long);
372 u_long convert_to_16bit(u_long);
373 int gus_mixer_set_port(void *, mixer_ctrl_t *);
374 int gus_mixer_get_port(void *, mixer_ctrl_t *);
375 int gusmax_mixer_set_port(void *, mixer_ctrl_t *);
376 int gusmax_mixer_get_port(void *, mixer_ctrl_t *);
377 int gus_mixer_query_devinfo(void *, mixer_devinfo_t *);
378 int gusmax_mixer_query_devinfo(void *, mixer_devinfo_t *);
379 int gus_query_encoding(void *, struct audio_encoding *);
380 int gus_get_props(void *);
381 int gusmax_get_props(void *);
382
383 void gusics_master_mute(struct ics2101_softc *, int);
384 void gusics_dac_mute(struct ics2101_softc *, int);
385 void gusics_mic_mute(struct ics2101_softc *, int);
386 void gusics_linein_mute(struct ics2101_softc *, int);
387 void gusics_cd_mute(struct ics2101_softc *, int);
388
389 void stereo_dmaintr(void *);
390
391 extern const int gus_irq_map[];
392 extern const int gus_drq_map[];
393 extern const int gus_base_addrs[];
394 extern const int gus_addrs;
395 extern const int gus_max_frequency[];
396
397 extern const ushort gus_log_volumes[];
398
399 #define SELECT_GUS_REG(iot,ioh1,x) bus_space_write_1(iot,ioh1,GUS_REG_SELECT,x)
400 #define ADDR_HIGH(x) (unsigned int) ((x >> 7L) & 0x1fffL)
401 #define ADDR_LOW(x) (unsigned int) ((x & 0x7fL) << 9L)
402
403 #define GUS_MIN_VOICES 14
404 #define GUS_MAX_VOICES 32
405 #define GUS_VOICE_LEFT 0
406 #define GUS_VOICE_RIGHT 1
407 #define GUS_MEM_OFFSET 32
408 #define GUS_BUFFER_MULTIPLE 1024
409 #define GUS_MEM_FOR_BUFFERS 131072
410 #define GUS_LEFT_RIGHT_OFFSET (sc->sc_nbufs * sc->sc_chanblocksize + GUS_MEM_OFFSET)
411
412 #define GUS_PREC_BYTES (sc->sc_precision >> 3)
413
414
415
416 #define splgus splaudio
417
418 extern struct audio_hw_if gus_hw_if;
419 extern struct audio_hw_if gusmax_hw_if;
420 extern struct audio_device gus_device;
421
422 #define FLIP_REV 5
423
424 void gus_subattach(struct gus_softc *, struct isa_attach_args *);