blob: 841bb8df38c1af1caacacba848aa9fb4b677be72 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __SOUND_GUS_H
2#define __SOUND_GUS_H
3
4/*
5 * Global structures used for GUS part of ALSA driver
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02006 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include "pcm.h"
26#include "rawmidi.h"
27#include "timer.h"
28#include "seq_midi_emul.h"
29#include "seq_device.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/io.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* IO ports */
33
34#define GUSP(gus, x) ((gus)->gf1.port + SNDRV_g_u_s_##x)
35
36#define SNDRV_g_u_s_MIDICTRL (0x320-0x220)
37#define SNDRV_g_u_s_MIDISTAT (0x320-0x220)
38#define SNDRV_g_u_s_MIDIDATA (0x321-0x220)
39
40#define SNDRV_g_u_s_GF1PAGE (0x322-0x220)
41#define SNDRV_g_u_s_GF1REGSEL (0x323-0x220)
42#define SNDRV_g_u_s_GF1DATALOW (0x324-0x220)
43#define SNDRV_g_u_s_GF1DATAHIGH (0x325-0x220)
44#define SNDRV_g_u_s_IRQSTAT (0x226-0x220)
45#define SNDRV_g_u_s_TIMERCNTRL (0x228-0x220)
46#define SNDRV_g_u_s_TIMERDATA (0x229-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010047#define SNDRV_g_u_s_DRAM (0x327-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define SNDRV_g_u_s_MIXCNTRLREG (0x220-0x220)
49#define SNDRV_g_u_s_IRQDMACNTRLREG (0x22b-0x220)
50#define SNDRV_g_u_s_REGCNTRLS (0x22f-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010051#define SNDRV_g_u_s_BOARDVERSION (0x726-0x220)
52#define SNDRV_g_u_s_MIXCNTRLPORT (0x726-0x220)
53#define SNDRV_g_u_s_IVER (0x325-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define SNDRV_g_u_s_MIXDATAPORT (0x326-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010055#define SNDRV_g_u_s_MAXCNTRLPORT (0x326-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/* GF1 registers */
58
59/* global registers */
60#define SNDRV_GF1_GB_ACTIVE_VOICES 0x0e
61#define SNDRV_GF1_GB_VOICES_IRQ 0x0f
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010062#define SNDRV_GF1_GB_GLOBAL_MODE 0x19
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define SNDRV_GF1_GW_LFO_BASE 0x1a
64#define SNDRV_GF1_GB_VOICES_IRQ_READ 0x1f
65#define SNDRV_GF1_GB_DRAM_DMA_CONTROL 0x41
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010066#define SNDRV_GF1_GW_DRAM_DMA_LOW 0x42
67#define SNDRV_GF1_GW_DRAM_IO_LOW 0x43
68#define SNDRV_GF1_GB_DRAM_IO_HIGH 0x44
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define SNDRV_GF1_GB_SOUND_BLASTER_CONTROL 0x45
70#define SNDRV_GF1_GB_ADLIB_TIMER_1 0x46
71#define SNDRV_GF1_GB_ADLIB_TIMER_2 0x47
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010072#define SNDRV_GF1_GB_RECORD_RATE 0x48
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define SNDRV_GF1_GB_REC_DMA_CONTROL 0x49
74#define SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL 0x4b
75#define SNDRV_GF1_GB_RESET 0x4c
76#define SNDRV_GF1_GB_DRAM_DMA_HIGH 0x50
77#define SNDRV_GF1_GW_DRAM_IO16 0x51
78#define SNDRV_GF1_GW_MEMORY_CONFIG 0x52
79#define SNDRV_GF1_GB_MEMORY_CONTROL 0x53
80#define SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR 0x54
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010081#define SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR 0x55
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define SNDRV_GF1_GW_FIFO_SIZE 0x56
83#define SNDRV_GF1_GW_INTERLEAVE 0x57
84#define SNDRV_GF1_GB_COMPATIBILITY 0x59
85#define SNDRV_GF1_GB_DECODE_CONTROL 0x5a
86#define SNDRV_GF1_GB_VERSION_NUMBER 0x5b
87#define SNDRV_GF1_GB_MPU401_CONTROL_A 0x5c
88#define SNDRV_GF1_GB_MPU401_CONTROL_B 0x5d
89#define SNDRV_GF1_GB_EMULATION_IRQ 0x60
90/* voice specific registers */
91#define SNDRV_GF1_VB_ADDRESS_CONTROL 0x00
92#define SNDRV_GF1_VW_FREQUENCY 0x01
93#define SNDRV_GF1_VW_START_HIGH 0x02
94#define SNDRV_GF1_VW_START_LOW 0x03
95#define SNDRV_GF1_VA_START SNDRV_GF1_VW_START_HIGH
96#define SNDRV_GF1_VW_END_HIGH 0x04
97#define SNDRV_GF1_VW_END_LOW 0x05
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010098#define SNDRV_GF1_VA_END SNDRV_GF1_VW_END_HIGH
99#define SNDRV_GF1_VB_VOLUME_RATE 0x06
100#define SNDRV_GF1_VB_VOLUME_START 0x07
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define SNDRV_GF1_VB_VOLUME_END 0x08
102#define SNDRV_GF1_VW_VOLUME 0x09
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100103#define SNDRV_GF1_VW_CURRENT_HIGH 0x0a
104#define SNDRV_GF1_VW_CURRENT_LOW 0x0b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define SNDRV_GF1_VA_CURRENT SNDRV_GF1_VW_CURRENT_HIGH
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100106#define SNDRV_GF1_VB_PAN 0x0c
107#define SNDRV_GF1_VW_OFFSET_RIGHT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define SNDRV_GF1_VB_VOLUME_CONTROL 0x0d
109#define SNDRV_GF1_VB_UPPER_ADDRESS 0x10
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100110#define SNDRV_GF1_VW_EFFECT_HIGH 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define SNDRV_GF1_VW_EFFECT_LOW 0x12
112#define SNDRV_GF1_VA_EFFECT SNDRV_GF1_VW_EFFECT_HIGH
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100113#define SNDRV_GF1_VW_OFFSET_LEFT 0x13
114#define SNDRV_GF1_VB_ACCUMULATOR 0x14
115#define SNDRV_GF1_VB_MODE 0x15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define SNDRV_GF1_VW_EFFECT_VOLUME 0x16
117#define SNDRV_GF1_VB_FREQUENCY_LFO 0x17
118#define SNDRV_GF1_VB_VOLUME_LFO 0x18
119#define SNDRV_GF1_VW_OFFSET_RIGHT_FINAL 0x1b
120#define SNDRV_GF1_VW_OFFSET_LEFT_FINAL 0x1c
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100121#define SNDRV_GF1_VW_EFFECT_VOLUME_FINAL 0x1d
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* ICS registers */
124
125#define SNDRV_ICS_MIC_DEV 0
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100126#define SNDRV_ICS_LINE_DEV 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define SNDRV_ICS_CD_DEV 2
128#define SNDRV_ICS_GF1_DEV 3
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100129#define SNDRV_ICS_NONE_DEV 4
130#define SNDRV_ICS_MASTER_DEV 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132/* LFO */
133
134#define SNDRV_LFO_TREMOLO 0
135#define SNDRV_LFO_VIBRATO 1
136
137/* misc */
138
139#define SNDRV_GF1_DMA_UNSIGNED 0x80
140#define SNDRV_GF1_DMA_16BIT 0x40
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100141#define SNDRV_GF1_DMA_IRQ 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define SNDRV_GF1_DMA_WIDTH16 0x04
143#define SNDRV_GF1_DMA_READ 0x02 /* read from GUS's DRAM */
144#define SNDRV_GF1_DMA_ENABLE 0x01
145
146/* ramp ranges */
147
148#define SNDRV_GF1_ATTEN(x) (snd_gf1_atten_table[x])
149#define SNDRV_GF1_MIN_VOLUME 1800
150#define SNDRV_GF1_MAX_VOLUME 4095
151#define SNDRV_GF1_MIN_OFFSET (SNDRV_GF1_MIN_VOLUME>>4)
152#define SNDRV_GF1_MAX_OFFSET 255
153#define SNDRV_GF1_MAX_TDEPTH 90
154
155/* defines for memory manager */
156
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100157#define SNDRV_GF1_MEM_BLOCK_16BIT 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159#define SNDRV_GF1_MEM_OWNER_DRIVER 0x0001
160#define SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE 0x0002
161#define SNDRV_GF1_MEM_OWNER_WAVE_GF1 0x0003
162#define SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF 0x0004
163
164/* constants for interrupt handlers */
165
166#define SNDRV_GF1_HANDLER_MIDI_OUT 0x00010000
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100167#define SNDRV_GF1_HANDLER_MIDI_IN 0x00020000
168#define SNDRV_GF1_HANDLER_TIMER1 0x00040000
169#define SNDRV_GF1_HANDLER_TIMER2 0x00080000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#define SNDRV_GF1_HANDLER_VOICE 0x00100000
171#define SNDRV_GF1_HANDLER_DMA_WRITE 0x00200000
172#define SNDRV_GF1_HANDLER_DMA_READ 0x00400000
173#define SNDRV_GF1_HANDLER_ALL (0xffff0000&~SNDRV_GF1_HANDLER_VOICE)
174
175/* constants for DMA flags */
176
177#define SNDRV_GF1_DMA_TRIGGER 1
178
179/* --- */
180
Takashi Iwai5e2da202005-11-17 14:36:44 +0100181struct snd_gus_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183/* GF1 specific structure */
184
Takashi Iwai5e2da202005-11-17 14:36:44 +0100185struct snd_gf1_bank_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 unsigned int address;
187 unsigned int size;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100188};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Takashi Iwai5e2da202005-11-17 14:36:44 +0100190struct snd_gf1_mem_block {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 unsigned short flags; /* flags - SNDRV_GF1_MEM_BLOCK_XXXX */
192 unsigned short owner; /* owner - SNDRV_GF1_MEM_OWNER_XXXX */
193 unsigned int share; /* share count */
194 unsigned int share_id[4]; /* share ID */
195 unsigned int ptr;
196 unsigned int size;
197 char *name;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100198 struct snd_gf1_mem_block *next;
199 struct snd_gf1_mem_block *prev;
200};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Takashi Iwai5e2da202005-11-17 14:36:44 +0100202struct snd_gf1_mem {
203 struct snd_gf1_bank_info banks_8[4];
204 struct snd_gf1_bank_info banks_16[4];
205 struct snd_gf1_mem_block *first;
206 struct snd_gf1_mem_block *last;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100207 struct mutex memory_mutex;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100208};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Takashi Iwai5e2da202005-11-17 14:36:44 +0100210struct snd_gf1_dma_block {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 void *buffer; /* buffer in computer's RAM */
212 unsigned long buf_addr; /* buffer address */
213 unsigned int addr; /* address in onboard memory */
214 unsigned int count; /* count in bytes */
215 unsigned int cmd; /* DMA command (format) */
Takashi Iwai5e2da202005-11-17 14:36:44 +0100216 void (*ack)(struct snd_gus_card * gus, void *private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 void *private_data;
218 struct snd_gf1_dma_block *next;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100219};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Takashi Iwai5e2da202005-11-17 14:36:44 +0100221struct snd_gus_port {
222 struct snd_midi_channel_set * chset;
223 struct snd_gus_card * gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 int mode; /* operation mode */
225 int client; /* sequencer client number */
226 int port; /* sequencer port number */
227 unsigned int midi_has_voices: 1;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100228};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Takashi Iwai5e2da202005-11-17 14:36:44 +0100230struct snd_gus_voice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Takashi Iwai5e2da202005-11-17 14:36:44 +0100232#define SNDRV_GF1_VOICE_TYPE_PCM 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define SNDRV_GF1_VOICE_TYPE_SYNTH 1
Takashi Iwai5e2da202005-11-17 14:36:44 +0100234#define SNDRV_GF1_VOICE_TYPE_MIDI 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236#define SNDRV_GF1_VFLG_RUNNING (1<<0)
237#define SNDRV_GF1_VFLG_EFFECT_TIMER1 (1<<1)
238#define SNDRV_GF1_VFLG_PAN (1<<2)
239
Takashi Iwai5e2da202005-11-17 14:36:44 +0100240enum snd_gus_volume_state {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 VENV_BEFORE,
242 VENV_ATTACK,
243 VENV_SUSTAIN,
244 VENV_RELEASE,
245 VENV_DONE,
246 VENV_VOLUME
Takashi Iwai5e2da202005-11-17 14:36:44 +0100247};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Takashi Iwai5e2da202005-11-17 14:36:44 +0100249struct snd_gus_voice {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 int number;
251 unsigned int use: 1,
252 pcm: 1,
253 synth:1,
254 midi: 1;
255 unsigned int flags;
256 unsigned char client;
257 unsigned char port;
258 unsigned char index;
259 unsigned char pad;
260
261#ifdef CONFIG_SND_DEBUG
262 unsigned int interrupt_stat_wave;
263 unsigned int interrupt_stat_volume;
264#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100265 void (*handler_wave) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
266 void (*handler_volume) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
267 void (*handler_effect) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
268 void (*volume_change) (struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Takashi Iwai5e2da202005-11-17 14:36:44 +0100270 struct snd_gus_sample_ops *sample_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* running status / registers */
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 unsigned short fc_register;
275 unsigned short fc_lfo;
276 unsigned short gf1_volume;
277 unsigned char control;
278 unsigned char mode;
279 unsigned char gf1_pan;
280 unsigned char effect_accumulator;
281 unsigned char volume_control;
282 unsigned char venv_value_next;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100283 enum snd_gus_volume_state venv_state;
284 enum snd_gus_volume_state venv_state_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 unsigned short vlo;
286 unsigned short vro;
287 unsigned short gf1_effect_volume;
288
289 /* --- */
290
291 void *private_data;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100292 void (*private_free)(struct snd_gus_voice *voice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293};
294
Takashi Iwai5e2da202005-11-17 14:36:44 +0100295struct snd_gf1 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 unsigned int enh_mode:1, /* enhanced mode (GFA1) */
298 hw_lfo:1, /* use hardware LFO */
299 sw_lfo:1, /* use software LFO */
300 effect:1; /* use effect voices */
301
302 unsigned long port; /* port of GF1 chip */
303 struct resource *res_port1;
304 struct resource *res_port2;
305 int irq; /* IRQ number */
306 int dma1; /* DMA1 number */
307 int dma2; /* DMA2 number */
308 unsigned int memory; /* GUS's DRAM size in bytes */
309 unsigned int rom_memory; /* GUS's ROM size in bytes */
310 unsigned int rom_present; /* bitmask */
311 unsigned int rom_banks; /* GUS's ROM banks */
312
Takashi Iwai5e2da202005-11-17 14:36:44 +0100313 struct snd_gf1_mem mem_alloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 /* registers */
316 unsigned short reg_page;
317 unsigned short reg_regsel;
318 unsigned short reg_data8;
319 unsigned short reg_data16;
320 unsigned short reg_irqstat;
321 unsigned short reg_dram;
322 unsigned short reg_timerctrl;
323 unsigned short reg_timerdata;
324 unsigned char ics_regs[6][2];
325 /* --------- */
326
327 unsigned char active_voices; /* active voices */
328 unsigned char active_voice; /* selected voice (GF1PAGE register) */
329
Takashi Iwai5e2da202005-11-17 14:36:44 +0100330 struct snd_gus_voice voices[32]; /* GF1 voices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 unsigned int default_voice_address;
333
334 unsigned short playback_freq; /* GF1 playback (mixing) frequency */
335 unsigned short mode; /* see to SNDRV_GF1_MODE_XXXX */
336 unsigned char volume_ramp;
337 unsigned char smooth_pan;
338 unsigned char full_range_pan;
339 unsigned char pad0;
340
341 unsigned char *lfos;
342
343 /* interrupt handlers */
344
Takashi Iwai5e2da202005-11-17 14:36:44 +0100345 void (*interrupt_handler_midi_out) (struct snd_gus_card * gus);
346 void (*interrupt_handler_midi_in) (struct snd_gus_card * gus);
347 void (*interrupt_handler_timer1) (struct snd_gus_card * gus);
348 void (*interrupt_handler_timer2) (struct snd_gus_card * gus);
349 void (*interrupt_handler_dma_write) (struct snd_gus_card * gus);
350 void (*interrupt_handler_dma_read) (struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352#ifdef CONFIG_SND_DEBUG
353 unsigned int interrupt_stat_midi_out;
354 unsigned int interrupt_stat_midi_in;
355 unsigned int interrupt_stat_timer1;
356 unsigned int interrupt_stat_timer2;
357 unsigned int interrupt_stat_dma_write;
358 unsigned int interrupt_stat_dma_read;
359 unsigned int interrupt_stat_voice_lost;
360#endif
361
362 /* synthesizer */
363
364 int seq_client;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100365 struct snd_gus_port seq_ports[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /* timer */
368
369 unsigned short timer_enabled;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100370 struct snd_timer *timer1;
371 struct snd_timer *timer2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 /* midi */
374
375 unsigned short uart_cmd;
376 unsigned int uart_framing;
377 unsigned int uart_overrun;
378
379 /* dma operations */
380
381 unsigned int dma_flags;
382 unsigned int dma_shared;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100383 struct snd_gf1_dma_block *dma_data_pcm;
384 struct snd_gf1_dma_block *dma_data_pcm_last;
385 struct snd_gf1_dma_block *dma_data_synth;
386 struct snd_gf1_dma_block *dma_data_synth_last;
387 void (*dma_ack)(struct snd_gus_card * gus, void *private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 void *dma_private_data;
389
390 /* pcm */
391 int pcm_channels;
392 int pcm_alloc_voices;
393 unsigned short pcm_volume_level_left;
394 unsigned short pcm_volume_level_right;
395 unsigned short pcm_volume_level_left1;
396 unsigned short pcm_volume_level_right1;
397
398 unsigned char pcm_rcntrl_reg;
399 unsigned char pad_end;
400};
401
402/* main structure for GUS card */
403
Takashi Iwai5e2da202005-11-17 14:36:44 +0100404struct snd_gus_card {
405 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 unsigned int
408 initialized: 1, /* resources were initialized */
409 equal_irq:1, /* GF1 and CODEC shares IRQ (GUS MAX only) */
410 equal_dma:1, /* if dma channels are equal (not valid for daughter board) */
411 ics_flag:1, /* have we ICS mixer chip */
412 ics_flipped:1, /* ICS mixer have flipped some channels? */
413 codec_flag:1, /* have we CODEC chip? */
414 max_flag:1, /* have we GUS MAX card? */
415 max_ctrl_flag:1, /* have we original GUS MAX card? */
416 daughter_flag:1, /* have we daughter board? */
417 interwave:1, /* hey - we have InterWave card */
418 ess_flag:1, /* ESS chip found... GUS Extreme */
419 ace_flag:1, /* GUS ACE detected */
420 uart_enable:1; /* enable MIDI UART */
421 unsigned short revision; /* revision of chip */
422 unsigned short max_cntrl_val; /* GUS MAX control value */
423 unsigned short mix_cntrl_reg; /* mixer control register */
424 unsigned short joystick_dac; /* joystick DAC level */
425 int timer_dev; /* timer device */
426
Takashi Iwai5e2da202005-11-17 14:36:44 +0100427 struct snd_gf1 gf1; /* gf1 specific variables */
428 struct snd_pcm *pcm;
429 struct snd_pcm_substream *pcm_cap_substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 unsigned int c_dma_size;
431 unsigned int c_period_size;
432 unsigned int c_pos;
433
Takashi Iwai5e2da202005-11-17 14:36:44 +0100434 struct snd_rawmidi *midi_uart;
435 struct snd_rawmidi_substream *midi_substream_output;
436 struct snd_rawmidi_substream *midi_substream_input;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 spinlock_t reg_lock;
439 spinlock_t voice_alloc;
440 spinlock_t active_voice_lock;
441 spinlock_t event_lock;
442 spinlock_t dma_lock;
443 spinlock_t pcm_volume_level_lock;
444 spinlock_t uart_cmd_lock;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100445 struct mutex dma_mutex;
446 struct mutex register_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447};
448
449/* I/O functions for GF1/InterWave chip - gus_io.c */
450
Takashi Iwai5e2da202005-11-17 14:36:44 +0100451static inline void snd_gf1_select_voice(struct snd_gus_card * gus, int voice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
453 unsigned long flags;
454
455 spin_lock_irqsave(&gus->active_voice_lock, flags);
456 if (voice != gus->gf1.active_voice) {
457 gus->gf1.active_voice = voice;
458 outb(voice, GUSP(gus, GF1PAGE));
459 }
460 spin_unlock_irqrestore(&gus->active_voice_lock, flags);
461}
462
Takashi Iwai5e2da202005-11-17 14:36:44 +0100463static inline void snd_gf1_uart_cmd(struct snd_gus_card * gus, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 outb(gus->gf1.uart_cmd = b, GUSP(gus, MIDICTRL));
466}
467
Takashi Iwai5e2da202005-11-17 14:36:44 +0100468static inline unsigned char snd_gf1_uart_stat(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 return inb(GUSP(gus, MIDISTAT));
471}
472
Takashi Iwai5e2da202005-11-17 14:36:44 +0100473static inline void snd_gf1_uart_put(struct snd_gus_card * gus, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 outb(b, GUSP(gus, MIDIDATA));
476}
477
Takashi Iwai5e2da202005-11-17 14:36:44 +0100478static inline unsigned char snd_gf1_uart_get(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 return inb(GUSP(gus, MIDIDATA));
481}
482
Takashi Iwai5e2da202005-11-17 14:36:44 +0100483extern void snd_gf1_delay(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Takashi Iwai5e2da202005-11-17 14:36:44 +0100485extern void snd_gf1_ctrl_stop(struct snd_gus_card * gus, unsigned char reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Takashi Iwai5e2da202005-11-17 14:36:44 +0100487extern void snd_gf1_write8(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
488extern unsigned char snd_gf1_look8(struct snd_gus_card * gus, unsigned char reg);
489static inline unsigned char snd_gf1_read8(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 return snd_gf1_look8(gus, reg | 0x80);
492}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100493extern void snd_gf1_write16(struct snd_gus_card * gus, unsigned char reg, unsigned int data);
494extern unsigned short snd_gf1_look16(struct snd_gus_card * gus, unsigned char reg);
495static inline unsigned short snd_gf1_read16(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 return snd_gf1_look16(gus, reg | 0x80);
498}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100499extern void snd_gf1_adlib_write(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
500extern void snd_gf1_dram_addr(struct snd_gus_card * gus, unsigned int addr);
501extern void snd_gf1_poke(struct snd_gus_card * gus, unsigned int addr, unsigned char data);
502extern unsigned char snd_gf1_peek(struct snd_gus_card * gus, unsigned int addr);
503extern void snd_gf1_write_addr(struct snd_gus_card * gus, unsigned char reg, unsigned int addr, short w_16bit);
504extern unsigned int snd_gf1_read_addr(struct snd_gus_card * gus, unsigned char reg, short w_16bit);
505extern void snd_gf1_i_ctrl_stop(struct snd_gus_card * gus, unsigned char reg);
506extern void snd_gf1_i_write8(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
507extern unsigned char snd_gf1_i_look8(struct snd_gus_card * gus, unsigned char reg);
508extern void snd_gf1_i_write16(struct snd_gus_card * gus, unsigned char reg, unsigned int data);
509static inline unsigned char snd_gf1_i_read8(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
511 return snd_gf1_i_look8(gus, reg | 0x80);
512}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100513extern unsigned short snd_gf1_i_look16(struct snd_gus_card * gus, unsigned char reg);
514static inline unsigned short snd_gf1_i_read16(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 return snd_gf1_i_look16(gus, reg | 0x80);
517}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Takashi Iwai5e2da202005-11-17 14:36:44 +0100519extern void snd_gf1_select_active_voices(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521/* gus_lfo.c */
522
523struct _SND_IW_LFO_PROGRAM {
524 unsigned short freq_and_control;
525 unsigned char depth_final;
526 unsigned char depth_inc;
527 unsigned short twave;
528 unsigned short depth;
529};
530
531#if 0
Takashi Iwai5e2da202005-11-17 14:36:44 +0100532extern irqreturn_t snd_gf1_lfo_effect_interrupt(struct snd_gus_card * gus, snd_gf1_voice_t * voice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100534extern void snd_gf1_lfo_init(struct snd_gus_card * gus);
535extern void snd_gf1_lfo_done(struct snd_gus_card * gus);
536extern void snd_gf1_lfo_program(struct snd_gus_card * gus, int voice, int lfo_type, struct _SND_IW_LFO_PROGRAM *program);
537extern void snd_gf1_lfo_enable(struct snd_gus_card * gus, int voice, int lfo_type);
538extern void snd_gf1_lfo_disable(struct snd_gus_card * gus, int voice, int lfo_type);
539extern void snd_gf1_lfo_change_freq(struct snd_gus_card * gus, int voice, int lfo_type, int freq);
540extern void snd_gf1_lfo_change_depth(struct snd_gus_card * gus, int voice, int lfo_type, int depth);
541extern void snd_gf1_lfo_setup(struct snd_gus_card * gus, int voice, int lfo_type, int freq, int current_depth, int depth, int sweep, int shape);
542extern void snd_gf1_lfo_shutdown(struct snd_gus_card * gus, int voice, int lfo_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#if 0
Takashi Iwai5e2da202005-11-17 14:36:44 +0100544extern void snd_gf1_lfo_command(struct snd_gus_card * gus, int voice, unsigned char *command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#endif
546
547/* gus_mem.c */
548
Takashi Iwai5e2da202005-11-17 14:36:44 +0100549void snd_gf1_mem_lock(struct snd_gf1_mem * alloc, int xup);
550int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * block);
551struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owner,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 char *name, int size, int w_16,
553 int align, unsigned int *share_id);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100554int snd_gf1_mem_free(struct snd_gf1_mem * alloc, unsigned int address);
555int snd_gf1_mem_free_owner(struct snd_gf1_mem * alloc, int owner);
556int snd_gf1_mem_init(struct snd_gus_card * gus);
557int snd_gf1_mem_done(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559/* gus_mem_proc.c */
560
Takashi Iwai5e2da202005-11-17 14:36:44 +0100561int snd_gf1_mem_proc_init(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563/* gus_dma.c */
564
Takashi Iwai5e2da202005-11-17 14:36:44 +0100565int snd_gf1_dma_init(struct snd_gus_card * gus);
566int snd_gf1_dma_done(struct snd_gus_card * gus);
567int snd_gf1_dma_transfer_block(struct snd_gus_card * gus,
568 struct snd_gf1_dma_block * block,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 int atomic,
570 int synth);
571
572/* gus_volume.c */
573
574unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100575unsigned short snd_gf1_translate_freq(struct snd_gus_card * gus, unsigned int freq2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577/* gus_reset.c */
578
Takashi Iwai5e2da202005-11-17 14:36:44 +0100579void snd_gf1_set_default_handlers(struct snd_gus_card * gus, unsigned int what);
580void snd_gf1_smart_stop_voice(struct snd_gus_card * gus, unsigned short voice);
581void snd_gf1_stop_voice(struct snd_gus_card * gus, unsigned short voice);
582void snd_gf1_stop_voices(struct snd_gus_card * gus, unsigned short v_min, unsigned short v_max);
583struct snd_gus_voice *snd_gf1_alloc_voice(struct snd_gus_card * gus, int type, int client, int port);
584void snd_gf1_free_voice(struct snd_gus_card * gus, struct snd_gus_voice *voice);
585int snd_gf1_start(struct snd_gus_card * gus);
586int snd_gf1_stop(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588/* gus_mixer.c */
589
Takashi Iwai5e2da202005-11-17 14:36:44 +0100590int snd_gf1_new_mixer(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592/* gus_pcm.c */
593
Takashi Iwai5e2da202005-11-17 14:36:44 +0100594int snd_gf1_pcm_new(struct snd_gus_card * gus, int pcm_dev, int control_index, struct snd_pcm ** rpcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596#ifdef CONFIG_SND_DEBUG
Takashi Iwai5e2da202005-11-17 14:36:44 +0100597extern void snd_gf1_print_voice_registers(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#endif
599
600/* gus.c */
601
Takashi Iwai5e2da202005-11-17 14:36:44 +0100602int snd_gus_use_inc(struct snd_gus_card * gus);
603void snd_gus_use_dec(struct snd_gus_card * gus);
604int snd_gus_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 unsigned long port,
606 int irq, int dma1, int dma2,
607 int timer_dev,
608 int voices,
609 int pcm_channels,
610 int effect,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100611 struct snd_gus_card ** rgus);
612int snd_gus_initialize(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614/* gus_irq.c */
615
David Howells7d12e782006-10-05 14:55:46 +0100616irqreturn_t snd_gus_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#ifdef CONFIG_SND_DEBUG
Takashi Iwai5e2da202005-11-17 14:36:44 +0100618void snd_gus_irq_profile_init(struct snd_gus_card *gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#endif
620
621/* gus_uart.c */
622
Takashi Iwai5e2da202005-11-17 14:36:44 +0100623int snd_gf1_rawmidi_new(struct snd_gus_card * gus, int device, struct snd_rawmidi **rrawmidi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625/* gus_dram.c */
Takashi Iwai5e2da202005-11-17 14:36:44 +0100626int snd_gus_dram_write(struct snd_gus_card *gus, char __user *ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 unsigned int addr, unsigned int size);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100628int snd_gus_dram_read(struct snd_gus_card *gus, char __user *ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 unsigned int addr, unsigned int size, int rom);
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#endif /* __SOUND_GUS_H */