[PATCH] swsusp: kill write-only variable
[linux-2.6/sactl.git] / include / sound / trident.h
blob9752243241e58b3524590a4225e6f53255ae0cbb
1 #ifndef __SOUND_TRIDENT_H
2 #define __SOUND_TRIDENT_H
4 /*
5 * audio@tridentmicro.com
6 * Fri Feb 19 15:55:28 MST 1999
7 * Definitions for Trident 4DWave DX/NX chips
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "pcm.h"
27 #include "mpu401.h"
28 #include "ac97_codec.h"
29 #include "seq_midi_emul.h"
30 #include "seq_device.h"
31 #include "util_mem.h"
32 //#include "ainstr_iw.h"
33 //#include "ainstr_gf1.h"
34 #include "ainstr_simple.h"
36 #define TRIDENT_DEVICE_ID_DX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_DX)
37 #define TRIDENT_DEVICE_ID_NX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_NX)
38 #define TRIDENT_DEVICE_ID_SI7018 ((PCI_VENDOR_ID_SI<<16)|PCI_DEVICE_ID_SI_7018)
40 #define SNDRV_SEQ_DEV_ID_TRIDENT "trident-synth"
42 #define SNDRV_TRIDENT_VOICE_TYPE_PCM 0
43 #define SNDRV_TRIDENT_VOICE_TYPE_SYNTH 1
44 #define SNDRV_TRIDENT_VOICE_TYPE_MIDI 2
46 #define SNDRV_TRIDENT_VFLG_RUNNING (1<<0)
48 /* TLB code constants */
49 #define SNDRV_TRIDENT_PAGE_SIZE 4096
50 #define SNDRV_TRIDENT_PAGE_SHIFT 12
51 #define SNDRV_TRIDENT_PAGE_MASK ((1<<SNDRV_TRIDENT_PAGE_SHIFT)-1)
52 #define SNDRV_TRIDENT_MAX_PAGES 4096
55 * Direct registers
58 #define TRID_REG(trident, x) ((trident)->port + (x))
60 #define ID_4DWAVE_DX 0x2000
61 #define ID_4DWAVE_NX 0x2001
63 /* Bank definitions */
65 #define T4D_BANK_A 0
66 #define T4D_BANK_B 1
67 #define T4D_NUM_BANKS 2
69 /* Register definitions */
71 /* Global registers */
73 enum global_control_bits {
74 CHANNEL_IDX = 0x0000003f,
75 OVERRUN_IE = 0x00000400, /* interrupt enable: capture overrun */
76 UNDERRUN_IE = 0x00000800, /* interrupt enable: playback underrun */
77 ENDLP_IE = 0x00001000, /* interrupt enable: end of buffer */
78 MIDLP_IE = 0x00002000, /* interrupt enable: middle buffer */
79 ETOG_IE = 0x00004000, /* interrupt enable: envelope toggling */
80 EDROP_IE = 0x00008000, /* interrupt enable: envelope drop */
81 BANK_B_EN = 0x00010000, /* SiS: enable bank B (64 channels) */
82 PCMIN_B_MIX = 0x00020000, /* SiS: PCM IN B mixing enable */
83 I2S_OUT_ASSIGN = 0x00040000, /* SiS: I2S Out contains surround PCM */
84 SPDIF_OUT_ASSIGN= 0x00080000, /* SiS: 0=S/PDIF L/R | 1=PCM Out FIFO */
85 MAIN_OUT_ASSIGN = 0x00100000, /* SiS: 0=PCM Out FIFO | 1=MMC Out buffer */
88 enum miscint_bits {
89 PB_UNDERRUN_IRQ = 0x00000001, REC_OVERRUN_IRQ = 0x00000002,
90 SB_IRQ = 0x00000004, MPU401_IRQ = 0x00000008,
91 OPL3_IRQ = 0x00000010, ADDRESS_IRQ = 0x00000020,
92 ENVELOPE_IRQ = 0x00000040, PB_UNDERRUN = 0x00000100,
93 REC_OVERRUN = 0x00000200, MIXER_UNDERFLOW = 0x00000400,
94 MIXER_OVERFLOW = 0x00000800, NX_SB_IRQ_DISABLE = 0x00001000,
95 ST_TARGET_REACHED = 0x00008000,
96 PB_24K_MODE = 0x00010000, ST_IRQ_EN = 0x00800000,
97 ACGPIO_IRQ = 0x01000000
100 /* T2 legacy dma control registers. */
101 #define LEGACY_DMAR0 0x00 // ADR0
102 #define LEGACY_DMAR4 0x04 // CNT0
103 #define LEGACY_DMAR6 0x06 // CNT0 - High bits
104 #define LEGACY_DMAR11 0x0b // MOD
105 #define LEGACY_DMAR15 0x0f // MMR
107 #define T4D_START_A 0x80
108 #define T4D_STOP_A 0x84
109 #define T4D_DLY_A 0x88
110 #define T4D_SIGN_CSO_A 0x8c
111 #define T4D_CSPF_A 0x90
112 #define T4D_CSPF_B 0xbc
113 #define T4D_CEBC_A 0x94
114 #define T4D_AINT_A 0x98
115 #define T4D_AINTEN_A 0x9c
116 #define T4D_LFO_GC_CIR 0xa0
117 #define T4D_MUSICVOL_WAVEVOL 0xa8
118 #define T4D_SBDELTA_DELTA_R 0xac
119 #define T4D_MISCINT 0xb0
120 #define T4D_START_B 0xb4
121 #define T4D_STOP_B 0xb8
122 #define T4D_SBBL_SBCL 0xc0
123 #define T4D_SBCTRL_SBE2R_SBDD 0xc4
124 #define T4D_STIMER 0xc8
125 #define T4D_AINT_B 0xd8
126 #define T4D_AINTEN_B 0xdc
127 #define T4D_RCI 0x70
129 /* MPU-401 UART */
130 #define T4D_MPU401_BASE 0x20
131 #define T4D_MPUR0 0x20
132 #define T4D_MPUR1 0x21
133 #define T4D_MPUR2 0x22
134 #define T4D_MPUR3 0x23
136 /* S/PDIF Registers */
137 #define NX_SPCTRL_SPCSO 0x24
138 #define NX_SPLBA 0x28
139 #define NX_SPESO 0x2c
140 #define NX_SPCSTATUS 0x64
142 /* Joystick */
143 #define GAMEPORT_GCR 0x30
144 #define GAMEPORT_MODE_ADC 0x80
145 #define GAMEPORT_LEGACY 0x31
146 #define GAMEPORT_AXES 0x34
148 /* NX Specific Registers */
149 #define NX_TLBC 0x6c
151 /* Channel Registers */
153 #define CH_START 0xe0
155 #define CH_DX_CSO_ALPHA_FMS 0xe0
156 #define CH_DX_ESO_DELTA 0xe8
157 #define CH_DX_FMC_RVOL_CVOL 0xec
159 #define CH_NX_DELTA_CSO 0xe0
160 #define CH_NX_DELTA_ESO 0xe8
161 #define CH_NX_ALPHA_FMS_FMC_RVOL_CVOL 0xec
163 #define CH_LBA 0xe4
164 #define CH_GVSEL_PAN_VOL_CTRL_EC 0xf0
165 #define CH_EBUF1 0xf4
166 #define CH_EBUF2 0xf8
168 /* AC-97 Registers */
170 #define DX_ACR0_AC97_W 0x40
171 #define DX_ACR1_AC97_R 0x44
172 #define DX_ACR2_AC97_COM_STAT 0x48
174 #define NX_ACR0_AC97_COM_STAT 0x40
175 #define NX_ACR1_AC97_W 0x44
176 #define NX_ACR2_AC97_R_PRIMARY 0x48
177 #define NX_ACR3_AC97_R_SECONDARY 0x4c
179 #define SI_AC97_WRITE 0x40
180 #define SI_AC97_READ 0x44
181 #define SI_SERIAL_INTF_CTRL 0x48
182 #define SI_AC97_GPIO 0x4c
183 #define SI_ASR0 0x50
184 #define SI_SPDIF_CS 0x70
185 #define SI_GPIO 0x7c
187 enum trident_nx_ac97_bits {
188 /* ACR1-3 */
189 NX_AC97_BUSY_WRITE = 0x0800,
190 NX_AC97_BUSY_READ = 0x0800,
191 NX_AC97_BUSY_DATA = 0x0400,
192 NX_AC97_WRITE_SECONDARY = 0x0100,
193 /* ACR0 */
194 NX_AC97_SECONDARY_READY = 0x0040,
195 NX_AC97_SECONDARY_RECORD = 0x0020,
196 NX_AC97_SURROUND_OUTPUT = 0x0010,
197 NX_AC97_PRIMARY_READY = 0x0008,
198 NX_AC97_PRIMARY_RECORD = 0x0004,
199 NX_AC97_PCM_OUTPUT = 0x0002,
200 NX_AC97_WARM_RESET = 0x0001
203 enum trident_dx_ac97_bits {
204 DX_AC97_BUSY_WRITE = 0x8000,
205 DX_AC97_BUSY_READ = 0x8000,
206 DX_AC97_READY = 0x0010,
207 DX_AC97_RECORD = 0x0008,
208 DX_AC97_PLAYBACK = 0x0002
211 enum sis7018_ac97_bits {
212 SI_AC97_BUSY_WRITE = 0x00008000,
213 SI_AC97_AUDIO_BUSY = 0x00004000,
214 SI_AC97_MODEM_BUSY = 0x00002000,
215 SI_AC97_BUSY_READ = 0x00008000,
216 SI_AC97_SECONDARY = 0x00000080,
219 enum serial_intf_ctrl_bits {
220 WARM_RESET = 0x00000001,
221 COLD_RESET = 0x00000002,
222 I2S_CLOCK = 0x00000004,
223 PCM_SEC_AC97 = 0x00000008,
224 AC97_DBL_RATE = 0x00000010,
225 SPDIF_EN = 0x00000020,
226 I2S_OUTPUT_EN = 0x00000040,
227 I2S_INPUT_EN = 0x00000080,
228 PCMIN = 0x00000100,
229 LINE1IN = 0x00000200,
230 MICIN = 0x00000400,
231 LINE2IN = 0x00000800,
232 HEAD_SET_IN = 0x00001000,
233 GPIOIN = 0x00002000,
234 /* 7018 spec says id = 01 but the demo board routed to 10
235 SECONDARY_ID= 0x00004000, */
236 SECONDARY_ID = 0x00004000,
237 PCMOUT = 0x00010000,
238 SURROUT = 0x00020000,
239 CENTEROUT = 0x00040000,
240 LFEOUT = 0x00080000,
241 LINE1OUT = 0x00100000,
242 LINE2OUT = 0x00200000,
243 GPIOOUT = 0x00400000,
244 SI_AC97_PRIMARY_READY = 0x01000000,
245 SI_AC97_SECONDARY_READY = 0x02000000,
246 SI_AC97_POWERDOWN = 0x04000000,
249 /* PCM defaults */
251 #define T4D_DEFAULT_PCM_VOL 10 /* 0 - 255 */
252 #define T4D_DEFAULT_PCM_PAN 0 /* 0 - 127 */
253 #define T4D_DEFAULT_PCM_RVOL 127 /* 0 - 127 */
254 #define T4D_DEFAULT_PCM_CVOL 127 /* 0 - 127 */
256 struct snd_trident;
257 struct snd_trident_voice;
258 struct snd_trident_pcm_mixer;
260 struct snd_trident_sample_ops {
261 void (*sample_start)(struct snd_trident *gus, struct snd_trident_voice *voice, snd_seq_position_t position);
262 void (*sample_stop)(struct snd_trident *gus, struct snd_trident_voice *voice, int mode);
263 void (*sample_freq)(struct snd_trident *gus, struct snd_trident_voice *voice, snd_seq_frequency_t freq);
264 void (*sample_volume)(struct snd_trident *gus, struct snd_trident_voice *voice, struct snd_seq_ev_volume *volume);
265 void (*sample_loop)(struct snd_trident *card, struct snd_trident_voice *voice, struct snd_seq_ev_loop *loop);
266 void (*sample_pos)(struct snd_trident *card, struct snd_trident_voice *voice, snd_seq_position_t position);
267 void (*sample_private1)(struct snd_trident *card, struct snd_trident_voice *voice, unsigned char *data);
270 struct snd_trident_port {
271 struct snd_midi_channel_set * chset;
272 struct snd_trident * trident;
273 int mode; /* operation mode */
274 int client; /* sequencer client number */
275 int port; /* sequencer port number */
276 unsigned int midi_has_voices: 1;
279 struct snd_trident_memblk_arg {
280 short first_page, last_page;
283 struct snd_trident_tlb {
284 unsigned int * entries; /* 16k-aligned TLB table */
285 dma_addr_t entries_dmaaddr; /* 16k-aligned PCI address to TLB table */
286 unsigned long * shadow_entries; /* shadow entries with virtual addresses */
287 struct snd_dma_buffer buffer;
288 struct snd_util_memhdr * memhdr; /* page allocation list */
289 struct snd_dma_buffer silent_page;
292 struct snd_trident_voice {
293 unsigned int number;
294 unsigned int use: 1,
295 pcm: 1,
296 synth:1,
297 midi: 1;
298 unsigned int flags;
299 unsigned char client;
300 unsigned char port;
301 unsigned char index;
303 struct snd_seq_instr instr;
304 struct snd_trident_sample_ops *sample_ops;
306 /* channel parameters */
307 unsigned int CSO; /* 24 bits (16 on DX) */
308 unsigned int ESO; /* 24 bits (16 on DX) */
309 unsigned int LBA; /* 30 bits */
310 unsigned short EC; /* 12 bits */
311 unsigned short Alpha; /* 12 bits */
312 unsigned short Delta; /* 16 bits */
313 unsigned short Attribute; /* 16 bits - SiS 7018 */
314 unsigned short Vol; /* 12 bits (6.6) */
315 unsigned char Pan; /* 7 bits (1.4.2) */
316 unsigned char GVSel; /* 1 bit */
317 unsigned char RVol; /* 7 bits (5.2) */
318 unsigned char CVol; /* 7 bits (5.2) */
319 unsigned char FMC; /* 2 bits */
320 unsigned char CTRL; /* 4 bits */
321 unsigned char FMS; /* 4 bits */
322 unsigned char LFO; /* 8 bits */
324 unsigned int negCSO; /* nonzero - use negative CSO */
326 struct snd_util_memblk *memblk; /* memory block if TLB enabled */
328 /* PCM data */
330 struct snd_trident *trident;
331 struct snd_pcm_substream *substream;
332 struct snd_trident_voice *extra; /* extra PCM voice (acts as interrupt generator) */
333 unsigned int running: 1,
334 capture: 1,
335 spdif: 1,
336 foldback: 1,
337 isync: 1,
338 isync2: 1,
339 isync3: 1;
340 int foldback_chan; /* foldback subdevice number */
341 unsigned int stimer; /* global sample timer (to detect spurious interrupts) */
342 unsigned int spurious_threshold; /* spurious threshold */
343 unsigned int isync_mark;
344 unsigned int isync_max;
345 unsigned int isync_ESO;
347 /* --- */
349 void *private_data;
350 void (*private_free)(struct snd_trident_voice *voice);
353 struct snd_4dwave {
354 int seq_client;
356 struct snd_trident_port seq_ports[4];
357 struct snd_simple_ops simple_ops;
358 struct snd_seq_kinstr_list *ilist;
360 struct snd_trident_voice voices[64];
362 int ChanSynthCount; /* number of allocated synth channels */
363 int max_size; /* maximum synth memory size in bytes */
364 int current_size; /* current allocated synth mem in bytes */
367 struct snd_trident_pcm_mixer {
368 struct snd_trident_voice *voice; /* active voice */
369 unsigned short vol; /* front volume */
370 unsigned char pan; /* pan control */
371 unsigned char rvol; /* rear volume */
372 unsigned char cvol; /* center volume */
373 unsigned char pad;
376 struct snd_trident {
377 int irq;
379 unsigned int device; /* device ID */
381 unsigned char bDMAStart;
383 unsigned long port;
384 unsigned long midi_port;
386 unsigned int spurious_irq_count;
387 unsigned int spurious_irq_max_delta;
389 struct snd_trident_tlb tlb; /* TLB entries for NX cards */
391 unsigned char spdif_ctrl;
392 unsigned char spdif_pcm_ctrl;
393 unsigned int spdif_bits;
394 unsigned int spdif_pcm_bits;
395 struct snd_kcontrol *spdif_pcm_ctl; /* S/PDIF settings */
396 unsigned int ac97_ctrl;
398 unsigned int ChanMap[2]; /* allocation map for hardware channels */
400 int ChanPCM; /* max number of PCM channels */
401 int ChanPCMcnt; /* actual number of PCM channels */
403 unsigned int ac97_detect: 1; /* 1 = AC97 in detection phase */
404 unsigned int in_suspend: 1; /* 1 during suspend/resume */
406 struct snd_4dwave synth; /* synth specific variables */
408 spinlock_t event_lock;
409 spinlock_t voice_alloc;
411 struct snd_dma_device dma_dev;
413 struct pci_dev *pci;
414 struct snd_card *card;
415 struct snd_pcm *pcm; /* ADC/DAC PCM */
416 struct snd_pcm *foldback; /* Foldback PCM */
417 struct snd_pcm *spdif; /* SPDIF PCM */
418 struct snd_rawmidi *rmidi;
419 struct snd_seq_device *seq_dev;
421 struct snd_ac97_bus *ac97_bus;
422 struct snd_ac97 *ac97;
423 struct snd_ac97 *ac97_sec;
425 unsigned int musicvol_wavevol;
426 struct snd_trident_pcm_mixer pcm_mixer[32];
427 struct snd_kcontrol *ctl_vol; /* front volume */
428 struct snd_kcontrol *ctl_pan; /* pan */
429 struct snd_kcontrol *ctl_rvol; /* rear volume */
430 struct snd_kcontrol *ctl_cvol; /* center volume */
432 spinlock_t reg_lock;
434 struct gameport *gameport;
437 int snd_trident_create(struct snd_card *card,
438 struct pci_dev *pci,
439 int pcm_streams,
440 int pcm_spdif_device,
441 int max_wavetable_size,
442 struct snd_trident ** rtrident);
443 int snd_trident_create_gameport(struct snd_trident *trident);
445 int snd_trident_pcm(struct snd_trident * trident, int device, struct snd_pcm **rpcm);
446 int snd_trident_foldback_pcm(struct snd_trident * trident, int device, struct snd_pcm **rpcm);
447 int snd_trident_spdif_pcm(struct snd_trident * trident, int device, struct snd_pcm **rpcm);
448 int snd_trident_attach_synthesizer(struct snd_trident * trident);
449 struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type,
450 int client, int port);
451 void snd_trident_free_voice(struct snd_trident * trident, struct snd_trident_voice *voice);
452 void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice);
453 void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice);
454 void snd_trident_write_voice_regs(struct snd_trident * trident, struct snd_trident_voice *voice);
455 int snd_trident_suspend(struct pci_dev *pci, pm_message_t state);
456 int snd_trident_resume(struct pci_dev *pci);
458 /* TLB memory allocation */
459 struct snd_util_memblk *snd_trident_alloc_pages(struct snd_trident *trident,
460 struct snd_pcm_substream *substream);
461 int snd_trident_free_pages(struct snd_trident *trident, struct snd_util_memblk *blk);
462 struct snd_util_memblk *snd_trident_synth_alloc(struct snd_trident *trident, unsigned int size);
463 int snd_trident_synth_free(struct snd_trident *trident, struct snd_util_memblk *blk);
464 int snd_trident_synth_copy_from_user(struct snd_trident *trident, struct snd_util_memblk *blk,
465 int offset, const char __user *data, int size);
467 #endif /* __SOUND_TRIDENT_H */