blob: 4e62ee1e4115222ad42c1fb52beea6c03b27da52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __SOUND_SB_H
2#define __SOUND_SB_H
3
4/*
5 * Header file for SoundBlaster cards
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 <linux/interrupt.h>
28#include <asm/io.h>
29
30enum sb_hw_type {
31 SB_HW_AUTO,
32 SB_HW_10,
33 SB_HW_20,
34 SB_HW_201,
35 SB_HW_PRO,
36 SB_HW_16,
37 SB_HW_16CSP, /* SB16 with CSP chip */
38 SB_HW_ALS100, /* Avance Logic ALS100 chip */
39 SB_HW_ALS4000, /* Avance Logic ALS4000 chip */
40 SB_HW_DT019X, /* Diamond Tech. DT-019X / Avance Logic ALS-007 */
Takashi Iwai621887a2007-05-24 18:46:54 +020041 SB_HW_CS5530, /* Cyrix/NatSemi 5530 VSA1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
44#define SB_OPEN_PCM 0x01
45#define SB_OPEN_MIDI_INPUT 0x02
46#define SB_OPEN_MIDI_OUTPUT 0x04
47#define SB_OPEN_MIDI_INPUT_TRIGGER 0x08
48#define SB_OPEN_MIDI_OUTPUT_TRIGGER 0x10
49
50#define SB_MODE_HALT 0x00
51#define SB_MODE_PLAYBACK_8 0x01
52#define SB_MODE_PLAYBACK_16 0x02
53#define SB_MODE_PLAYBACK (SB_MODE_PLAYBACK_8 | SB_MODE_PLAYBACK_16)
54#define SB_MODE_CAPTURE_8 0x04
55#define SB_MODE_CAPTURE_16 0x08
56#define SB_MODE_CAPTURE (SB_MODE_CAPTURE_8 | SB_MODE_CAPTURE_16)
57
58#define SB_RATE_LOCK_PLAYBACK 0x10
59#define SB_RATE_LOCK_CAPTURE 0x20
60#define SB_RATE_LOCK (SB_RATE_LOCK_PLAYBACK | SB_RATE_LOCK_CAPTURE)
61
62#define SB_MPU_INPUT 1
63
Takashi Iwai029d64b2005-11-17 14:34:36 +010064struct snd_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 unsigned long port; /* base port of DSP chip */
66 struct resource *res_port;
67 unsigned long mpu_port; /* MPU port for SB DSP 4.0+ */
68 int irq; /* IRQ number of DSP chip */
69 int dma8; /* 8-bit DMA */
70 int dma16; /* 16-bit DMA */
71 unsigned short version; /* version of DSP chip */
72 enum sb_hw_type hardware; /* see to SB_HW_XXXX */
73
74 unsigned long alt_port; /* alternate port (ALS4000) */
75 struct pci_dev *pci; /* ALS4000 */
76
77 unsigned int open; /* see to SB_OPEN_XXXX for sb8 */
78 /* also SNDRV_SB_CSP_MODE_XXX for sb16_csp */
79 unsigned int mode; /* current mode of stream */
80 unsigned int force_mode16; /* force 16-bit mode of streams */
81 unsigned int locked_rate; /* sb16 duplex */
82 unsigned int playback_format;
83 unsigned int capture_format;
84 struct timer_list midi_timer;
85 unsigned int p_dma_size;
86 unsigned int p_period_size;
87 unsigned int c_dma_size;
88 unsigned int c_period_size;
89
90 spinlock_t mixer_lock;
91
92 char name[32];
93
94 void *csp; /* used only when CONFIG_SND_SB16_CSP is set */
95
Takashi Iwai029d64b2005-11-17 14:34:36 +010096 struct snd_card *card;
97 struct snd_pcm *pcm;
98 struct snd_pcm_substream *playback_substream;
99 struct snd_pcm_substream *capture_substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Takashi Iwai029d64b2005-11-17 14:34:36 +0100101 struct snd_rawmidi *rmidi;
102 struct snd_rawmidi_substream *midi_substream_input;
103 struct snd_rawmidi_substream *midi_substream_output;
David Howells7d12e782006-10-05 14:55:46 +0100104 irq_handler_t rmidi_callback;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 spinlock_t reg_lock;
107 spinlock_t open_lock;
108 spinlock_t midi_input_lock;
109
Takashi Iwai029d64b2005-11-17 14:34:36 +0100110 struct snd_info_entry *proc_entry;
Takashi Iwai5bdb6a12005-11-17 16:16:10 +0100111
112#ifdef CONFIG_PM
113 unsigned char saved_regs[0x20];
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* I/O ports */
118
119#define SBP(chip, x) ((chip)->port + s_b_SB_##x)
120#define SBP1(port, x) ((port) + s_b_SB_##x)
121
122#define s_b_SB_RESET 0x6
123#define s_b_SB_READ 0xa
124#define s_b_SB_WRITE 0xc
125#define s_b_SB_COMMAND 0xc
126#define s_b_SB_STATUS 0xc
127#define s_b_SB_DATA_AVAIL 0xe
128#define s_b_SB_DATA_AVAIL_16 0xf
129#define s_b_SB_MIXER_ADDR 0x4
130#define s_b_SB_MIXER_DATA 0x5
131#define s_b_SB_OPL3_LEFT 0x0
132#define s_b_SB_OPL3_RIGHT 0x2
133#define s_b_SB_OPL3_BOTH 0x8
134
135#define SB_DSP_OUTPUT 0x14
136#define SB_DSP_INPUT 0x24
137#define SB_DSP_BLOCK_SIZE 0x48
138#define SB_DSP_HI_OUTPUT 0x91
139#define SB_DSP_HI_INPUT 0x99
140#define SB_DSP_LO_OUTPUT_AUTO 0x1c
141#define SB_DSP_LO_INPUT_AUTO 0x2c
142#define SB_DSP_HI_OUTPUT_AUTO 0x90
143#define SB_DSP_HI_INPUT_AUTO 0x98
144#define SB_DSP_IMMED_INT 0xf2
145#define SB_DSP_GET_VERSION 0xe1
146#define SB_DSP_SPEAKER_ON 0xd1
147#define SB_DSP_SPEAKER_OFF 0xd3
148#define SB_DSP_DMA8_OFF 0xd0
149#define SB_DSP_DMA8_ON 0xd4
150#define SB_DSP_DMA8_EXIT 0xda
151#define SB_DSP_DMA16_OFF 0xd5
152#define SB_DSP_DMA16_ON 0xd6
153#define SB_DSP_DMA16_EXIT 0xd9
154#define SB_DSP_SAMPLE_RATE 0x40
155#define SB_DSP_SAMPLE_RATE_OUT 0x41
156#define SB_DSP_SAMPLE_RATE_IN 0x42
157#define SB_DSP_MONO_8BIT 0xa0
158#define SB_DSP_MONO_16BIT 0xa4
159#define SB_DSP_STEREO_8BIT 0xa8
160#define SB_DSP_STEREO_16BIT 0xac
161
162#define SB_DSP_MIDI_INPUT_IRQ 0x31
163#define SB_DSP_MIDI_UART_IRQ 0x35
164#define SB_DSP_MIDI_OUTPUT 0x38
165
166#define SB_DSP4_OUT8_AI 0xc6
167#define SB_DSP4_IN8_AI 0xce
168#define SB_DSP4_OUT16_AI 0xb6
169#define SB_DSP4_IN16_AI 0xbe
170#define SB_DSP4_MODE_UNS_MONO 0x00
171#define SB_DSP4_MODE_SIGN_MONO 0x10
172#define SB_DSP4_MODE_UNS_STEREO 0x20
173#define SB_DSP4_MODE_SIGN_STEREO 0x30
174
175#define SB_DSP4_OUTPUT 0x3c
176#define SB_DSP4_INPUT_LEFT 0x3d
177#define SB_DSP4_INPUT_RIGHT 0x3e
178
179/* registers for SB 2.0 mixer */
180#define SB_DSP20_MASTER_DEV 0x02
181#define SB_DSP20_PCM_DEV 0x0A
182#define SB_DSP20_CD_DEV 0x08
183#define SB_DSP20_FM_DEV 0x06
184
185/* registers for SB PRO mixer */
186#define SB_DSP_MASTER_DEV 0x22
187#define SB_DSP_PCM_DEV 0x04
188#define SB_DSP_LINE_DEV 0x2e
189#define SB_DSP_CD_DEV 0x28
190#define SB_DSP_FM_DEV 0x26
191#define SB_DSP_MIC_DEV 0x0a
192#define SB_DSP_CAPTURE_SOURCE 0x0c
193#define SB_DSP_CAPTURE_FILT 0x0c
194#define SB_DSP_PLAYBACK_FILT 0x0e
195#define SB_DSP_STEREO_SW 0x0e
196
197#define SB_DSP_MIXS_MIC0 0x00 /* same as MIC */
198#define SB_DSP_MIXS_CD 0x01
199#define SB_DSP_MIXS_MIC 0x02
200#define SB_DSP_MIXS_LINE 0x03
201
202/* registers (only for left channel) for SB 16 mixer */
203#define SB_DSP4_MASTER_DEV 0x30
204#define SB_DSP4_BASS_DEV 0x46
205#define SB_DSP4_TREBLE_DEV 0x44
206#define SB_DSP4_SYNTH_DEV 0x34
207#define SB_DSP4_PCM_DEV 0x32
208#define SB_DSP4_SPEAKER_DEV 0x3b
209#define SB_DSP4_LINE_DEV 0x38
210#define SB_DSP4_MIC_DEV 0x3a
211#define SB_DSP4_OUTPUT_SW 0x3c
212#define SB_DSP4_CD_DEV 0x36
213#define SB_DSP4_IGAIN_DEV 0x3f
214#define SB_DSP4_OGAIN_DEV 0x41
215#define SB_DSP4_MIC_AGC 0x43
216
217/* additional registers for SB 16 mixer */
218#define SB_DSP4_IRQSETUP 0x80
219#define SB_DSP4_DMASETUP 0x81
220#define SB_DSP4_IRQSTATUS 0x82
221#define SB_DSP4_MPUSETUP 0x84
222
223#define SB_DSP4_3DSE 0x90
224
225/* Registers for DT-019x / ALS-007 mixer */
226#define SB_DT019X_MASTER_DEV 0x62
227#define SB_DT019X_PCM_DEV 0x64
228#define SB_DT019X_SYNTH_DEV 0x66
229#define SB_DT019X_CD_DEV 0x68
230#define SB_DT019X_MIC_DEV 0x6a
231#define SB_DT019X_SPKR_DEV 0x6a
232#define SB_DT019X_LINE_DEV 0x6e
233#define SB_DT019X_OUTPUT_SW2 0x4c
234#define SB_DT019X_CAPTURE_SW 0x6c
235
236#define SB_DT019X_CAP_CD 0x02
237#define SB_DT019X_CAP_MIC 0x04
238#define SB_DT019X_CAP_LINE 0x06
239#define SB_DT019X_CAP_SYNTH 0x07
240#define SB_DT019X_CAP_MAIN 0x07
241
242#define SB_ALS4000_MONO_IO_CTRL 0x4b
Andreas Mohrcb780cd2008-08-21 21:55:57 +0200243#define SB_ALS4000_OUT_MIXER_CTRL_2 0x4c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define SB_ALS4000_MIC_IN_GAIN 0x4d
Andreas Mohrcb780cd2008-08-21 21:55:57 +0200245#define SB_ALS4000_ANALOG_REFRNC_VOLT_CTRL 0x4e
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#define SB_ALS4000_FMDAC 0x4f
247#define SB_ALS4000_3D_SND_FX 0x50
248#define SB_ALS4000_3D_TIME_DELAY 0x51
249#define SB_ALS4000_3D_AUTO_MUTE 0x52
Andreas Mohrcb780cd2008-08-21 21:55:57 +0200250#define SB_ALS4000_ANALOG_BLOCK_CTRL 0x53
251#define SB_ALS4000_3D_DELAYLINE_PATTERN 0x54
Andreas Mohrce71bfd2009-02-22 20:33:41 +0100252#define SB_ALS4000_CR3_CONFIGURATION 0xc3 /* bit 7 is Digital Loop Enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define SB_ALS4000_QSOUND 0xdb
254
255/* IRQ setting bitmap */
256#define SB_IRQSETUP_IRQ9 0x01
257#define SB_IRQSETUP_IRQ5 0x02
258#define SB_IRQSETUP_IRQ7 0x04
259#define SB_IRQSETUP_IRQ10 0x08
260
261/* IRQ types */
262#define SB_IRQTYPE_8BIT 0x01
263#define SB_IRQTYPE_16BIT 0x02
264#define SB_IRQTYPE_MPUIN 0x04
Andreas Mohrcb780cd2008-08-21 21:55:57 +0200265#define ALS4K_IRQTYPE_CR1E_DMA 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267/* DMA setting bitmap */
268#define SB_DMASETUP_DMA0 0x01
269#define SB_DMASETUP_DMA1 0x02
270#define SB_DMASETUP_DMA3 0x08
271#define SB_DMASETUP_DMA5 0x20
272#define SB_DMASETUP_DMA6 0x40
273#define SB_DMASETUP_DMA7 0x80
274
275/*
276 *
277 */
278
Takashi Iwai029d64b2005-11-17 14:34:36 +0100279static inline void snd_sb_ack_8bit(struct snd_sb *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 inb(SBP(chip, DATA_AVAIL));
282}
283
Takashi Iwai029d64b2005-11-17 14:34:36 +0100284static inline void snd_sb_ack_16bit(struct snd_sb *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 inb(SBP(chip, DATA_AVAIL_16));
287}
288
289/* sb_common.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100290int snd_sbdsp_command(struct snd_sb *chip, unsigned char val);
291int snd_sbdsp_get_byte(struct snd_sb *chip);
292int snd_sbdsp_reset(struct snd_sb *chip);
293int snd_sbdsp_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 unsigned long port,
295 int irq,
David Howells7d12e782006-10-05 14:55:46 +0100296 irq_handler_t irq_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 int dma8, int dma16,
298 unsigned short hardware,
Takashi Iwai029d64b2005-11-17 14:34:36 +0100299 struct snd_sb **r_chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/* sb_mixer.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100301void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data);
302unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg);
303int snd_sbmixer_new(struct snd_sb *chip);
Takashi Iwai5bdb6a12005-11-17 16:16:10 +0100304#ifdef CONFIG_PM
305void snd_sbmixer_suspend(struct snd_sb *chip);
306void snd_sbmixer_resume(struct snd_sb *chip);
307#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309/* sb8_init.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100310int snd_sb8dsp_pcm(struct snd_sb *chip, int device, struct snd_pcm ** rpcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/* sb8.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100312irqreturn_t snd_sb8dsp_interrupt(struct snd_sb *chip);
313int snd_sb8_playback_open(struct snd_pcm_substream *substream);
314int snd_sb8_capture_open(struct snd_pcm_substream *substream);
315int snd_sb8_playback_close(struct snd_pcm_substream *substream);
316int snd_sb8_capture_close(struct snd_pcm_substream *substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/* midi8.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100318irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip);
319int snd_sb8dsp_midi(struct snd_sb *chip, int device, struct snd_rawmidi ** rrawmidi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321/* sb16_init.c */
Takashi Iwai029d64b2005-11-17 14:34:36 +0100322int snd_sb16dsp_pcm(struct snd_sb *chip, int device, struct snd_pcm ** rpcm);
323const struct snd_pcm_ops *snd_sb16dsp_get_pcm_ops(int direction);
324int snd_sb16dsp_configure(struct snd_sb *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325/* sb16.c */
David Howells7d12e782006-10-05 14:55:46 +0100326irqreturn_t snd_sb16dsp_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328/* exported mixer stuffs */
329enum {
330 SB_MIX_SINGLE,
331 SB_MIX_DOUBLE,
332 SB_MIX_INPUT_SW,
333 SB_MIX_CAPTURE_PRO,
Andreas Mohrce71bfd2009-02-22 20:33:41 +0100334 SB_MIX_CAPTURE_DT019X,
335 SB_MIX_MONO_CAPTURE_ALS4K
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336};
337
338#define SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) \
339 ((left_reg) | ((right_reg) << 8) | ((left_shift) << 16) | ((right_shift) << 19) | ((mask) << 24))
340#define SB_MIXVAL_SINGLE(reg, shift, mask) \
341 ((reg) | ((shift) << 16) | ((mask) << 24))
342#define SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) \
343 ((reg1) | ((reg2) << 8) | ((left_shift) << 16) | ((right_shift) << 24))
344
Takashi Iwai029d64b2005-11-17 14:34:36 +0100345int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347/* for ease of use */
348struct sbmix_elem {
349 const char *name;
350 int type;
351 unsigned long private_value;
352};
353
354#define SB_SINGLE(xname, reg, shift, mask) \
355{ .name = xname, \
356 .type = SB_MIX_SINGLE, \
357 .private_value = SB_MIXVAL_SINGLE(reg, shift, mask) }
358
359#define SB_DOUBLE(xname, left_reg, right_reg, left_shift, right_shift, mask) \
360{ .name = xname, \
361 .type = SB_MIX_DOUBLE, \
362 .private_value = SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) }
363
364#define SB16_INPUT_SW(xname, reg1, reg2, left_shift, right_shift) \
365{ .name = xname, \
366 .type = SB_MIX_INPUT_SW, \
367 .private_value = SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) }
368
Takashi Iwai029d64b2005-11-17 14:34:36 +0100369static inline int snd_sbmixer_add_ctl_elem(struct snd_sb *chip, const struct sbmix_elem *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
371 return snd_sbmixer_add_ctl(chip, c->name, 0, c->type, c->private_value);
372}
373
374#endif /* __SOUND_SB_H */