blob: cd8da68cab9216599ea51ca9f0020f6249cb0fbc [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __SOUND_GUS_H
3#define __SOUND_GUS_H
4
5/*
6 * Global structures used for GUS part of ALSA driver
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02007 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
David Howellsa1ce39282012-10-02 18:01:25 +010010#include <sound/pcm.h>
11#include <sound/rawmidi.h>
12#include <sound/timer.h>
13#include <sound/seq_midi_emul.h>
14#include <sound/seq_device.h>
Takashi Iwai6cbbfe12015-01-28 16:49:33 +010015#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/* IO ports */
18
19#define GUSP(gus, x) ((gus)->gf1.port + SNDRV_g_u_s_##x)
20
21#define SNDRV_g_u_s_MIDICTRL (0x320-0x220)
22#define SNDRV_g_u_s_MIDISTAT (0x320-0x220)
23#define SNDRV_g_u_s_MIDIDATA (0x321-0x220)
24
25#define SNDRV_g_u_s_GF1PAGE (0x322-0x220)
26#define SNDRV_g_u_s_GF1REGSEL (0x323-0x220)
27#define SNDRV_g_u_s_GF1DATALOW (0x324-0x220)
28#define SNDRV_g_u_s_GF1DATAHIGH (0x325-0x220)
29#define SNDRV_g_u_s_IRQSTAT (0x226-0x220)
30#define SNDRV_g_u_s_TIMERCNTRL (0x228-0x220)
31#define SNDRV_g_u_s_TIMERDATA (0x229-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010032#define SNDRV_g_u_s_DRAM (0x327-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define SNDRV_g_u_s_MIXCNTRLREG (0x220-0x220)
34#define SNDRV_g_u_s_IRQDMACNTRLREG (0x22b-0x220)
35#define SNDRV_g_u_s_REGCNTRLS (0x22f-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010036#define SNDRV_g_u_s_BOARDVERSION (0x726-0x220)
37#define SNDRV_g_u_s_MIXCNTRLPORT (0x726-0x220)
38#define SNDRV_g_u_s_IVER (0x325-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define SNDRV_g_u_s_MIXDATAPORT (0x326-0x220)
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010040#define SNDRV_g_u_s_MAXCNTRLPORT (0x326-0x220)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/* GF1 registers */
43
44/* global registers */
45#define SNDRV_GF1_GB_ACTIVE_VOICES 0x0e
46#define SNDRV_GF1_GB_VOICES_IRQ 0x0f
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010047#define SNDRV_GF1_GB_GLOBAL_MODE 0x19
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define SNDRV_GF1_GW_LFO_BASE 0x1a
49#define SNDRV_GF1_GB_VOICES_IRQ_READ 0x1f
50#define SNDRV_GF1_GB_DRAM_DMA_CONTROL 0x41
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010051#define SNDRV_GF1_GW_DRAM_DMA_LOW 0x42
52#define SNDRV_GF1_GW_DRAM_IO_LOW 0x43
53#define SNDRV_GF1_GB_DRAM_IO_HIGH 0x44
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define SNDRV_GF1_GB_SOUND_BLASTER_CONTROL 0x45
55#define SNDRV_GF1_GB_ADLIB_TIMER_1 0x46
56#define SNDRV_GF1_GB_ADLIB_TIMER_2 0x47
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010057#define SNDRV_GF1_GB_RECORD_RATE 0x48
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define SNDRV_GF1_GB_REC_DMA_CONTROL 0x49
59#define SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL 0x4b
60#define SNDRV_GF1_GB_RESET 0x4c
61#define SNDRV_GF1_GB_DRAM_DMA_HIGH 0x50
62#define SNDRV_GF1_GW_DRAM_IO16 0x51
63#define SNDRV_GF1_GW_MEMORY_CONFIG 0x52
64#define SNDRV_GF1_GB_MEMORY_CONTROL 0x53
65#define SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR 0x54
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010066#define SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR 0x55
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define SNDRV_GF1_GW_FIFO_SIZE 0x56
68#define SNDRV_GF1_GW_INTERLEAVE 0x57
69#define SNDRV_GF1_GB_COMPATIBILITY 0x59
70#define SNDRV_GF1_GB_DECODE_CONTROL 0x5a
71#define SNDRV_GF1_GB_VERSION_NUMBER 0x5b
72#define SNDRV_GF1_GB_MPU401_CONTROL_A 0x5c
73#define SNDRV_GF1_GB_MPU401_CONTROL_B 0x5d
74#define SNDRV_GF1_GB_EMULATION_IRQ 0x60
75/* voice specific registers */
76#define SNDRV_GF1_VB_ADDRESS_CONTROL 0x00
77#define SNDRV_GF1_VW_FREQUENCY 0x01
78#define SNDRV_GF1_VW_START_HIGH 0x02
79#define SNDRV_GF1_VW_START_LOW 0x03
80#define SNDRV_GF1_VA_START SNDRV_GF1_VW_START_HIGH
81#define SNDRV_GF1_VW_END_HIGH 0x04
82#define SNDRV_GF1_VW_END_LOW 0x05
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010083#define SNDRV_GF1_VA_END SNDRV_GF1_VW_END_HIGH
84#define SNDRV_GF1_VB_VOLUME_RATE 0x06
85#define SNDRV_GF1_VB_VOLUME_START 0x07
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define SNDRV_GF1_VB_VOLUME_END 0x08
87#define SNDRV_GF1_VW_VOLUME 0x09
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010088#define SNDRV_GF1_VW_CURRENT_HIGH 0x0a
89#define SNDRV_GF1_VW_CURRENT_LOW 0x0b
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define SNDRV_GF1_VA_CURRENT SNDRV_GF1_VW_CURRENT_HIGH
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010091#define SNDRV_GF1_VB_PAN 0x0c
92#define SNDRV_GF1_VW_OFFSET_RIGHT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define SNDRV_GF1_VB_VOLUME_CONTROL 0x0d
94#define SNDRV_GF1_VB_UPPER_ADDRESS 0x10
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010095#define SNDRV_GF1_VW_EFFECT_HIGH 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define SNDRV_GF1_VW_EFFECT_LOW 0x12
97#define SNDRV_GF1_VA_EFFECT SNDRV_GF1_VW_EFFECT_HIGH
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +010098#define SNDRV_GF1_VW_OFFSET_LEFT 0x13
99#define SNDRV_GF1_VB_ACCUMULATOR 0x14
100#define SNDRV_GF1_VB_MODE 0x15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define SNDRV_GF1_VW_EFFECT_VOLUME 0x16
102#define SNDRV_GF1_VB_FREQUENCY_LFO 0x17
103#define SNDRV_GF1_VB_VOLUME_LFO 0x18
104#define SNDRV_GF1_VW_OFFSET_RIGHT_FINAL 0x1b
105#define SNDRV_GF1_VW_OFFSET_LEFT_FINAL 0x1c
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100106#define SNDRV_GF1_VW_EFFECT_VOLUME_FINAL 0x1d
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108/* ICS registers */
109
110#define SNDRV_ICS_MIC_DEV 0
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100111#define SNDRV_ICS_LINE_DEV 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define SNDRV_ICS_CD_DEV 2
113#define SNDRV_ICS_GF1_DEV 3
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100114#define SNDRV_ICS_NONE_DEV 4
115#define SNDRV_ICS_MASTER_DEV 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117/* LFO */
118
119#define SNDRV_LFO_TREMOLO 0
120#define SNDRV_LFO_VIBRATO 1
121
122/* misc */
123
124#define SNDRV_GF1_DMA_UNSIGNED 0x80
125#define SNDRV_GF1_DMA_16BIT 0x40
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100126#define SNDRV_GF1_DMA_IRQ 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define SNDRV_GF1_DMA_WIDTH16 0x04
128#define SNDRV_GF1_DMA_READ 0x02 /* read from GUS's DRAM */
129#define SNDRV_GF1_DMA_ENABLE 0x01
130
131/* ramp ranges */
132
133#define SNDRV_GF1_ATTEN(x) (snd_gf1_atten_table[x])
134#define SNDRV_GF1_MIN_VOLUME 1800
135#define SNDRV_GF1_MAX_VOLUME 4095
136#define SNDRV_GF1_MIN_OFFSET (SNDRV_GF1_MIN_VOLUME>>4)
137#define SNDRV_GF1_MAX_OFFSET 255
138#define SNDRV_GF1_MAX_TDEPTH 90
139
140/* defines for memory manager */
141
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100142#define SNDRV_GF1_MEM_BLOCK_16BIT 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144#define SNDRV_GF1_MEM_OWNER_DRIVER 0x0001
145#define SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE 0x0002
146#define SNDRV_GF1_MEM_OWNER_WAVE_GF1 0x0003
147#define SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF 0x0004
148
149/* constants for interrupt handlers */
150
151#define SNDRV_GF1_HANDLER_MIDI_OUT 0x00010000
Takashi Iwaibc1ff7f2005-11-17 10:28:15 +0100152#define SNDRV_GF1_HANDLER_MIDI_IN 0x00020000
153#define SNDRV_GF1_HANDLER_TIMER1 0x00040000
154#define SNDRV_GF1_HANDLER_TIMER2 0x00080000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define SNDRV_GF1_HANDLER_VOICE 0x00100000
156#define SNDRV_GF1_HANDLER_DMA_WRITE 0x00200000
157#define SNDRV_GF1_HANDLER_DMA_READ 0x00400000
158#define SNDRV_GF1_HANDLER_ALL (0xffff0000&~SNDRV_GF1_HANDLER_VOICE)
159
160/* constants for DMA flags */
161
162#define SNDRV_GF1_DMA_TRIGGER 1
163
164/* --- */
165
Takashi Iwai5e2da202005-11-17 14:36:44 +0100166struct snd_gus_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168/* GF1 specific structure */
169
Takashi Iwai5e2da202005-11-17 14:36:44 +0100170struct snd_gf1_bank_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 unsigned int address;
172 unsigned int size;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100173};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Takashi Iwai5e2da202005-11-17 14:36:44 +0100175struct snd_gf1_mem_block {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 unsigned short flags; /* flags - SNDRV_GF1_MEM_BLOCK_XXXX */
177 unsigned short owner; /* owner - SNDRV_GF1_MEM_OWNER_XXXX */
178 unsigned int share; /* share count */
179 unsigned int share_id[4]; /* share ID */
180 unsigned int ptr;
181 unsigned int size;
182 char *name;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100183 struct snd_gf1_mem_block *next;
184 struct snd_gf1_mem_block *prev;
185};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Takashi Iwai5e2da202005-11-17 14:36:44 +0100187struct snd_gf1_mem {
188 struct snd_gf1_bank_info banks_8[4];
189 struct snd_gf1_bank_info banks_16[4];
190 struct snd_gf1_mem_block *first;
191 struct snd_gf1_mem_block *last;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100192 struct mutex memory_mutex;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100193};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Takashi Iwai5e2da202005-11-17 14:36:44 +0100195struct snd_gf1_dma_block {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 void *buffer; /* buffer in computer's RAM */
197 unsigned long buf_addr; /* buffer address */
198 unsigned int addr; /* address in onboard memory */
199 unsigned int count; /* count in bytes */
200 unsigned int cmd; /* DMA command (format) */
Takashi Iwai5e2da202005-11-17 14:36:44 +0100201 void (*ack)(struct snd_gus_card * gus, void *private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 void *private_data;
203 struct snd_gf1_dma_block *next;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100204};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Takashi Iwai5e2da202005-11-17 14:36:44 +0100206struct snd_gus_port {
207 struct snd_midi_channel_set * chset;
208 struct snd_gus_card * gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 int mode; /* operation mode */
210 int client; /* sequencer client number */
211 int port; /* sequencer port number */
212 unsigned int midi_has_voices: 1;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100213};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Takashi Iwai5e2da202005-11-17 14:36:44 +0100215struct snd_gus_voice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Takashi Iwai5e2da202005-11-17 14:36:44 +0100217#define SNDRV_GF1_VOICE_TYPE_PCM 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#define SNDRV_GF1_VOICE_TYPE_SYNTH 1
Takashi Iwai5e2da202005-11-17 14:36:44 +0100219#define SNDRV_GF1_VOICE_TYPE_MIDI 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#define SNDRV_GF1_VFLG_RUNNING (1<<0)
222#define SNDRV_GF1_VFLG_EFFECT_TIMER1 (1<<1)
223#define SNDRV_GF1_VFLG_PAN (1<<2)
224
Takashi Iwai5e2da202005-11-17 14:36:44 +0100225enum snd_gus_volume_state {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 VENV_BEFORE,
227 VENV_ATTACK,
228 VENV_SUSTAIN,
229 VENV_RELEASE,
230 VENV_DONE,
231 VENV_VOLUME
Takashi Iwai5e2da202005-11-17 14:36:44 +0100232};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Takashi Iwai5e2da202005-11-17 14:36:44 +0100234struct snd_gus_voice {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 int number;
236 unsigned int use: 1,
237 pcm: 1,
238 synth:1,
239 midi: 1;
240 unsigned int flags;
241 unsigned char client;
242 unsigned char port;
243 unsigned char index;
244 unsigned char pad;
245
246#ifdef CONFIG_SND_DEBUG
247 unsigned int interrupt_stat_wave;
248 unsigned int interrupt_stat_volume;
249#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100250 void (*handler_wave) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
251 void (*handler_volume) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
252 void (*handler_effect) (struct snd_gus_card * gus, struct snd_gus_voice * voice);
253 void (*volume_change) (struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Takashi Iwai5e2da202005-11-17 14:36:44 +0100255 struct snd_gus_sample_ops *sample_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* running status / registers */
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 unsigned short fc_register;
260 unsigned short fc_lfo;
261 unsigned short gf1_volume;
262 unsigned char control;
263 unsigned char mode;
264 unsigned char gf1_pan;
265 unsigned char effect_accumulator;
266 unsigned char volume_control;
267 unsigned char venv_value_next;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100268 enum snd_gus_volume_state venv_state;
269 enum snd_gus_volume_state venv_state_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 unsigned short vlo;
271 unsigned short vro;
272 unsigned short gf1_effect_volume;
273
274 /* --- */
275
276 void *private_data;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100277 void (*private_free)(struct snd_gus_voice *voice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278};
279
Takashi Iwai5e2da202005-11-17 14:36:44 +0100280struct snd_gf1 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 unsigned int enh_mode:1, /* enhanced mode (GFA1) */
283 hw_lfo:1, /* use hardware LFO */
284 sw_lfo:1, /* use software LFO */
285 effect:1; /* use effect voices */
286
287 unsigned long port; /* port of GF1 chip */
288 struct resource *res_port1;
289 struct resource *res_port2;
290 int irq; /* IRQ number */
291 int dma1; /* DMA1 number */
292 int dma2; /* DMA2 number */
293 unsigned int memory; /* GUS's DRAM size in bytes */
294 unsigned int rom_memory; /* GUS's ROM size in bytes */
295 unsigned int rom_present; /* bitmask */
296 unsigned int rom_banks; /* GUS's ROM banks */
297
Takashi Iwai5e2da202005-11-17 14:36:44 +0100298 struct snd_gf1_mem mem_alloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 /* registers */
301 unsigned short reg_page;
302 unsigned short reg_regsel;
303 unsigned short reg_data8;
304 unsigned short reg_data16;
305 unsigned short reg_irqstat;
306 unsigned short reg_dram;
307 unsigned short reg_timerctrl;
308 unsigned short reg_timerdata;
309 unsigned char ics_regs[6][2];
310 /* --------- */
311
312 unsigned char active_voices; /* active voices */
313 unsigned char active_voice; /* selected voice (GF1PAGE register) */
314
Takashi Iwai5e2da202005-11-17 14:36:44 +0100315 struct snd_gus_voice voices[32]; /* GF1 voices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 unsigned int default_voice_address;
318
319 unsigned short playback_freq; /* GF1 playback (mixing) frequency */
320 unsigned short mode; /* see to SNDRV_GF1_MODE_XXXX */
321 unsigned char volume_ramp;
322 unsigned char smooth_pan;
323 unsigned char full_range_pan;
324 unsigned char pad0;
325
326 unsigned char *lfos;
327
328 /* interrupt handlers */
329
Takashi Iwai5e2da202005-11-17 14:36:44 +0100330 void (*interrupt_handler_midi_out) (struct snd_gus_card * gus);
331 void (*interrupt_handler_midi_in) (struct snd_gus_card * gus);
332 void (*interrupt_handler_timer1) (struct snd_gus_card * gus);
333 void (*interrupt_handler_timer2) (struct snd_gus_card * gus);
334 void (*interrupt_handler_dma_write) (struct snd_gus_card * gus);
335 void (*interrupt_handler_dma_read) (struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337#ifdef CONFIG_SND_DEBUG
338 unsigned int interrupt_stat_midi_out;
339 unsigned int interrupt_stat_midi_in;
340 unsigned int interrupt_stat_timer1;
341 unsigned int interrupt_stat_timer2;
342 unsigned int interrupt_stat_dma_write;
343 unsigned int interrupt_stat_dma_read;
344 unsigned int interrupt_stat_voice_lost;
345#endif
346
347 /* synthesizer */
348
349 int seq_client;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100350 struct snd_gus_port seq_ports[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 /* timer */
353
354 unsigned short timer_enabled;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100355 struct snd_timer *timer1;
356 struct snd_timer *timer2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* midi */
359
360 unsigned short uart_cmd;
361 unsigned int uart_framing;
362 unsigned int uart_overrun;
363
364 /* dma operations */
365
366 unsigned int dma_flags;
367 unsigned int dma_shared;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100368 struct snd_gf1_dma_block *dma_data_pcm;
369 struct snd_gf1_dma_block *dma_data_pcm_last;
370 struct snd_gf1_dma_block *dma_data_synth;
371 struct snd_gf1_dma_block *dma_data_synth_last;
372 void (*dma_ack)(struct snd_gus_card * gus, void *private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 void *dma_private_data;
374
375 /* pcm */
376 int pcm_channels;
377 int pcm_alloc_voices;
378 unsigned short pcm_volume_level_left;
379 unsigned short pcm_volume_level_right;
380 unsigned short pcm_volume_level_left1;
381 unsigned short pcm_volume_level_right1;
382
383 unsigned char pcm_rcntrl_reg;
384 unsigned char pad_end;
385};
386
387/* main structure for GUS card */
388
Takashi Iwai5e2da202005-11-17 14:36:44 +0100389struct snd_gus_card {
390 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 unsigned int
393 initialized: 1, /* resources were initialized */
394 equal_irq:1, /* GF1 and CODEC shares IRQ (GUS MAX only) */
395 equal_dma:1, /* if dma channels are equal (not valid for daughter board) */
396 ics_flag:1, /* have we ICS mixer chip */
397 ics_flipped:1, /* ICS mixer have flipped some channels? */
398 codec_flag:1, /* have we CODEC chip? */
399 max_flag:1, /* have we GUS MAX card? */
400 max_ctrl_flag:1, /* have we original GUS MAX card? */
401 daughter_flag:1, /* have we daughter board? */
402 interwave:1, /* hey - we have InterWave card */
403 ess_flag:1, /* ESS chip found... GUS Extreme */
404 ace_flag:1, /* GUS ACE detected */
405 uart_enable:1; /* enable MIDI UART */
406 unsigned short revision; /* revision of chip */
407 unsigned short max_cntrl_val; /* GUS MAX control value */
408 unsigned short mix_cntrl_reg; /* mixer control register */
409 unsigned short joystick_dac; /* joystick DAC level */
410 int timer_dev; /* timer device */
411
Takashi Iwai5e2da202005-11-17 14:36:44 +0100412 struct snd_gf1 gf1; /* gf1 specific variables */
413 struct snd_pcm *pcm;
414 struct snd_pcm_substream *pcm_cap_substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 unsigned int c_dma_size;
416 unsigned int c_period_size;
417 unsigned int c_pos;
418
Takashi Iwai5e2da202005-11-17 14:36:44 +0100419 struct snd_rawmidi *midi_uart;
420 struct snd_rawmidi_substream *midi_substream_output;
421 struct snd_rawmidi_substream *midi_substream_input;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 spinlock_t reg_lock;
424 spinlock_t voice_alloc;
425 spinlock_t active_voice_lock;
426 spinlock_t event_lock;
427 spinlock_t dma_lock;
428 spinlock_t pcm_volume_level_lock;
429 spinlock_t uart_cmd_lock;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100430 struct mutex dma_mutex;
431 struct mutex register_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432};
433
434/* I/O functions for GF1/InterWave chip - gus_io.c */
435
Takashi Iwai5e2da202005-11-17 14:36:44 +0100436static inline void snd_gf1_select_voice(struct snd_gus_card * gus, int voice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 unsigned long flags;
439
440 spin_lock_irqsave(&gus->active_voice_lock, flags);
441 if (voice != gus->gf1.active_voice) {
442 gus->gf1.active_voice = voice;
443 outb(voice, GUSP(gus, GF1PAGE));
444 }
445 spin_unlock_irqrestore(&gus->active_voice_lock, flags);
446}
447
Takashi Iwai5e2da202005-11-17 14:36:44 +0100448static inline void snd_gf1_uart_cmd(struct snd_gus_card * gus, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 outb(gus->gf1.uart_cmd = b, GUSP(gus, MIDICTRL));
451}
452
Takashi Iwai5e2da202005-11-17 14:36:44 +0100453static inline unsigned char snd_gf1_uart_stat(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
455 return inb(GUSP(gus, MIDISTAT));
456}
457
Takashi Iwai5e2da202005-11-17 14:36:44 +0100458static inline void snd_gf1_uart_put(struct snd_gus_card * gus, unsigned char b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
460 outb(b, GUSP(gus, MIDIDATA));
461}
462
Takashi Iwai5e2da202005-11-17 14:36:44 +0100463static inline unsigned char snd_gf1_uart_get(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 return inb(GUSP(gus, MIDIDATA));
466}
467
Takashi Iwai5e2da202005-11-17 14:36:44 +0100468extern void snd_gf1_delay(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Takashi Iwai5e2da202005-11-17 14:36:44 +0100470extern void snd_gf1_ctrl_stop(struct snd_gus_card * gus, unsigned char reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Takashi Iwai5e2da202005-11-17 14:36:44 +0100472extern void snd_gf1_write8(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
473extern unsigned char snd_gf1_look8(struct snd_gus_card * gus, unsigned char reg);
474static inline unsigned char snd_gf1_read8(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 return snd_gf1_look8(gus, reg | 0x80);
477}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100478extern void snd_gf1_write16(struct snd_gus_card * gus, unsigned char reg, unsigned int data);
479extern unsigned short snd_gf1_look16(struct snd_gus_card * gus, unsigned char reg);
480static inline unsigned short snd_gf1_read16(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
482 return snd_gf1_look16(gus, reg | 0x80);
483}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100484extern void snd_gf1_adlib_write(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
485extern void snd_gf1_dram_addr(struct snd_gus_card * gus, unsigned int addr);
486extern void snd_gf1_poke(struct snd_gus_card * gus, unsigned int addr, unsigned char data);
487extern unsigned char snd_gf1_peek(struct snd_gus_card * gus, unsigned int addr);
488extern void snd_gf1_write_addr(struct snd_gus_card * gus, unsigned char reg, unsigned int addr, short w_16bit);
489extern unsigned int snd_gf1_read_addr(struct snd_gus_card * gus, unsigned char reg, short w_16bit);
490extern void snd_gf1_i_ctrl_stop(struct snd_gus_card * gus, unsigned char reg);
491extern void snd_gf1_i_write8(struct snd_gus_card * gus, unsigned char reg, unsigned char data);
492extern unsigned char snd_gf1_i_look8(struct snd_gus_card * gus, unsigned char reg);
493extern void snd_gf1_i_write16(struct snd_gus_card * gus, unsigned char reg, unsigned int data);
494static inline unsigned char snd_gf1_i_read8(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 return snd_gf1_i_look8(gus, reg | 0x80);
497}
Takashi Iwai5e2da202005-11-17 14:36:44 +0100498extern unsigned short snd_gf1_i_look16(struct snd_gus_card * gus, unsigned char reg);
499static inline unsigned short snd_gf1_i_read16(struct snd_gus_card * gus, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 return snd_gf1_i_look16(gus, reg | 0x80);
502}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Takashi Iwai5e2da202005-11-17 14:36:44 +0100504extern void snd_gf1_select_active_voices(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506/* gus_lfo.c */
507
508struct _SND_IW_LFO_PROGRAM {
509 unsigned short freq_and_control;
510 unsigned char depth_final;
511 unsigned char depth_inc;
512 unsigned short twave;
513 unsigned short depth;
514};
515
516#if 0
Takashi Iwai5e2da202005-11-17 14:36:44 +0100517extern irqreturn_t snd_gf1_lfo_effect_interrupt(struct snd_gus_card * gus, snd_gf1_voice_t * voice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100519extern void snd_gf1_lfo_init(struct snd_gus_card * gus);
520extern void snd_gf1_lfo_done(struct snd_gus_card * gus);
521extern void snd_gf1_lfo_program(struct snd_gus_card * gus, int voice, int lfo_type, struct _SND_IW_LFO_PROGRAM *program);
522extern void snd_gf1_lfo_enable(struct snd_gus_card * gus, int voice, int lfo_type);
523extern void snd_gf1_lfo_disable(struct snd_gus_card * gus, int voice, int lfo_type);
524extern void snd_gf1_lfo_change_freq(struct snd_gus_card * gus, int voice, int lfo_type, int freq);
525extern void snd_gf1_lfo_change_depth(struct snd_gus_card * gus, int voice, int lfo_type, int depth);
526extern 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);
527extern void snd_gf1_lfo_shutdown(struct snd_gus_card * gus, int voice, int lfo_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528#if 0
Takashi Iwai5e2da202005-11-17 14:36:44 +0100529extern void snd_gf1_lfo_command(struct snd_gus_card * gus, int voice, unsigned char *command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#endif
531
532/* gus_mem.c */
533
Takashi Iwai5e2da202005-11-17 14:36:44 +0100534void snd_gf1_mem_lock(struct snd_gf1_mem * alloc, int xup);
535int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * block);
536struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owner,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 char *name, int size, int w_16,
538 int align, unsigned int *share_id);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100539int snd_gf1_mem_free(struct snd_gf1_mem * alloc, unsigned int address);
540int snd_gf1_mem_free_owner(struct snd_gf1_mem * alloc, int owner);
541int snd_gf1_mem_init(struct snd_gus_card * gus);
542int snd_gf1_mem_done(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544/* gus_mem_proc.c */
545
Takashi Iwai5e2da202005-11-17 14:36:44 +0100546int snd_gf1_mem_proc_init(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548/* gus_dma.c */
549
Takashi Iwai5e2da202005-11-17 14:36:44 +0100550int snd_gf1_dma_init(struct snd_gus_card * gus);
551int snd_gf1_dma_done(struct snd_gus_card * gus);
552int snd_gf1_dma_transfer_block(struct snd_gus_card * gus,
553 struct snd_gf1_dma_block * block,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 int atomic,
555 int synth);
556
557/* gus_volume.c */
558
559unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100560unsigned short snd_gf1_translate_freq(struct snd_gus_card * gus, unsigned int freq2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562/* gus_reset.c */
563
Takashi Iwai5e2da202005-11-17 14:36:44 +0100564void snd_gf1_set_default_handlers(struct snd_gus_card * gus, unsigned int what);
565void snd_gf1_smart_stop_voice(struct snd_gus_card * gus, unsigned short voice);
566void snd_gf1_stop_voice(struct snd_gus_card * gus, unsigned short voice);
567void snd_gf1_stop_voices(struct snd_gus_card * gus, unsigned short v_min, unsigned short v_max);
568struct snd_gus_voice *snd_gf1_alloc_voice(struct snd_gus_card * gus, int type, int client, int port);
569void snd_gf1_free_voice(struct snd_gus_card * gus, struct snd_gus_voice *voice);
570int snd_gf1_start(struct snd_gus_card * gus);
571int snd_gf1_stop(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573/* gus_mixer.c */
574
Takashi Iwai5e2da202005-11-17 14:36:44 +0100575int snd_gf1_new_mixer(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577/* gus_pcm.c */
578
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100579int snd_gf1_pcm_new(struct snd_gus_card *gus, int pcm_dev, int control_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581#ifdef CONFIG_SND_DEBUG
Takashi Iwai5e2da202005-11-17 14:36:44 +0100582extern void snd_gf1_print_voice_registers(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#endif
584
585/* gus.c */
586
Takashi Iwai5e2da202005-11-17 14:36:44 +0100587int snd_gus_use_inc(struct snd_gus_card * gus);
588void snd_gus_use_dec(struct snd_gus_card * gus);
589int snd_gus_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 unsigned long port,
591 int irq, int dma1, int dma2,
592 int timer_dev,
593 int voices,
594 int pcm_channels,
595 int effect,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100596 struct snd_gus_card ** rgus);
597int snd_gus_initialize(struct snd_gus_card * gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599/* gus_irq.c */
600
David Howells7d12e782006-10-05 14:55:46 +0100601irqreturn_t snd_gus_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#ifdef CONFIG_SND_DEBUG
Takashi Iwai5e2da202005-11-17 14:36:44 +0100603void snd_gus_irq_profile_init(struct snd_gus_card *gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#endif
605
606/* gus_uart.c */
607
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100608int snd_gf1_rawmidi_new(struct snd_gus_card *gus, int device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610/* gus_dram.c */
Takashi Iwai5e2da202005-11-17 14:36:44 +0100611int snd_gus_dram_write(struct snd_gus_card *gus, char __user *ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 unsigned int addr, unsigned int size);
Takashi Iwai5e2da202005-11-17 14:36:44 +0100613int snd_gus_dram_read(struct snd_gus_card *gus, char __user *ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 unsigned int addr, unsigned int size, int rom);
615
Pierre-Louis Bossart65cec1e2020-07-02 14:35:42 -0500616/* gus_timer.c */
617void snd_gf1_timers_init(struct snd_gus_card *gus);
618void snd_gf1_timers_done(struct snd_gus_card *gus);
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#endif /* __SOUND_GUS_H */