Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / sound / pci / au88x0 / au88x0.h
blob4aad35bba11a7af57679d47da3002223cd0c14ba
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #ifndef __SOUND_AU88X0_H
18 #define __SOUND_AU88X0_H
20 #ifdef __KERNEL__
21 #include <linux/pci.h>
22 #include <asm/io.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/rawmidi.h>
26 #include <sound/mpu401.h>
27 #include <sound/hwdep.h>
28 #include <sound/ac97_codec.h>
30 #endif
32 #ifndef CHIP_AU8820
33 #include "au88x0_eq.h"
34 #include "au88x0_a3d.h"
35 #endif
36 #ifndef CHIP_AU8810
37 #include "au88x0_wt.h"
38 #endif
40 #define hwread(x,y) readl((x)+(y))
41 #define hwwrite(x,y,z) writel((z),(x)+(y))
43 /* Vortex MPU401 defines. */
44 #define MIDI_CLOCK_DIV 0x61
45 /* Standart MPU401 defines. */
46 #define MPU401_RESET 0xff
47 #define MPU401_ENTER_UART 0x3f
48 #define MPU401_ACK 0xfe
50 // Get src register value to convert from x to y.
51 #define SRC_RATIO(x,y) ((((x<<15)/y) + 1)/2)
53 /* FIFO software state constants. */
54 #define FIFO_STOP 0
55 #define FIFO_START 1
56 #define FIFO_PAUSE 2
58 /* IRQ flags */
59 #define IRQ_ERR_MASK 0x00ff
60 #define IRQ_FATAL 0x0001
61 #define IRQ_PARITY 0x0002
62 #define IRQ_REG 0x0004
63 #define IRQ_FIFO 0x0008
64 #define IRQ_DMA 0x0010
65 #define IRQ_PCMOUT 0x0020 /* PCM OUT page crossing */
66 #define IRQ_TIMER 0x1000
67 #define IRQ_MIDI 0x2000
68 #define IRQ_MODEM 0x4000
70 /* ADB Resource */
71 #define VORTEX_RESOURCE_DMA 0x00000000
72 #define VORTEX_RESOURCE_SRC 0x00000001
73 #define VORTEX_RESOURCE_MIXIN 0x00000002
74 #define VORTEX_RESOURCE_MIXOUT 0x00000003
75 #define VORTEX_RESOURCE_A3D 0x00000004
76 #define VORTEX_RESOURCE_LAST 0x00000005
78 /* codec io: VORTEX_CODEC_IO bits */
79 #define VORTEX_CODEC_ID_SHIFT 24
80 #define VORTEX_CODEC_WRITE 0x00800000
81 #define VORTEX_CODEC_ADDSHIFT 16
82 #define VORTEX_CODEC_ADDMASK 0x7f0000
83 #define VORTEX_CODEC_DATSHIFT 0
84 #define VORTEX_CODEC_DATMASK 0xffff
86 /* Check for SDAC bit in "Extended audio ID" AC97 register */
87 //#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80))
88 #define VORTEX_IS_QUAD(x) ((x)->isquad)
89 /* Check if chip has bug. */
90 #define IS_BAD_CHIP(x) (\
91 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_VORTEX_2) || \
92 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_ADVANTAGE))
95 /* PCM devices */
96 #define VORTEX_PCM_ADB 0
97 #define VORTEX_PCM_SPDIF 1
98 #define VORTEX_PCM_A3D 2
99 #define VORTEX_PCM_WT 3
100 #define VORTEX_PCM_I2S 4
101 #define VORTEX_PCM_LAST 5
103 #define MIX_CAPT(x) (vortex->mixcapt[x])
104 #define MIX_PLAYB(x) (vortex->mixplayb[x])
105 #define MIX_SPDIF(x) (vortex->mixspdif[x])
107 #define NR_WTPB 0x20 /* WT channels per eahc bank. */
109 /* Structs */
110 typedef struct {
111 //int this_08; /* Still unknown */
112 int fifo_enabled; /* this_24 */
113 int fifo_status; /* this_1c */
114 u32 dma_ctrl; /* this_78 (ADB), this_7c (WT) */
115 int dma_unknown; /* this_74 (ADB), this_78 (WT). WDM: +8 */
116 int cfg0;
117 int cfg1;
119 int nr_ch; /* Nr of PCM channels in use */
120 int type; /* Output type (ac97, a3d, spdif, i2s, dsp) */
121 int dma; /* Hardware DMA index. */
122 int dir; /* Stream Direction. */
123 u32 resources[5];
125 /* Virtual page extender stuff */
126 int nr_periods;
127 int period_bytes;
128 struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
129 int period_real;
130 int period_virt;
132 struct snd_pcm_substream *substream;
133 } stream_t;
135 typedef struct snd_vortex vortex_t;
136 struct snd_vortex {
137 /* ALSA structs. */
138 struct snd_card *card;
139 struct snd_pcm *pcm[VORTEX_PCM_LAST];
141 struct snd_rawmidi *rmidi; /* Legacy Midi interface. */
142 struct snd_ac97 *codec;
144 /* Stream structs. */
145 stream_t dma_adb[NR_ADB];
146 int spdif_sr;
147 #ifndef CHIP_AU8810
148 stream_t dma_wt[NR_WT];
149 wt_voice_t wt_voice[NR_WT]; /* WT register cache. */
150 char mixwt[(NR_WT / NR_WTPB) * 6]; /* WT mixin objects */
151 #endif
153 /* Global resources */
154 s8 mixcapt[2];
155 s8 mixplayb[4];
156 #ifndef CHIP_AU8820
157 s8 mixspdif[2];
158 s8 mixa3d[2]; /* mixers which collect all a3d streams. */
159 s8 mixxtlk[2]; /* crosstalk canceler mixer inputs. */
160 #endif
161 u32 fixed_res[5];
163 #ifndef CHIP_AU8820
164 /* Hardware equalizer structs */
165 eqlzr_t eq;
166 /* A3D structs */
167 a3dsrc_t a3d[NR_A3D];
168 /* Xtalk canceler */
169 int xt_mode; /* 1: speakers, 0:headphones. */
170 #endif
172 int isquad; /* cache of extended ID codec flag. */
174 /* Gameport stuff. */
175 struct gameport *gameport;
177 /* PCI hardware resources */
178 unsigned long io;
179 void __iomem *mmio;
180 unsigned int irq;
181 spinlock_t lock;
183 /* PCI device */
184 struct pci_dev *pci_dev;
185 u16 vendor;
186 u16 device;
187 u8 rev;
190 /* Functions. */
192 /* SRC */
193 static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
194 unsigned int cvrt, int dir);
196 /* DMA Engines. */
197 static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
198 struct snd_sg_buf * sgbuf, int size,
199 int count);
200 static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
201 int dir, int fmt, int d,
202 u32 offset);
203 static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
204 #ifndef CHIP_AU8810
205 static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
206 struct snd_sg_buf * sgbuf, int size,
207 int count);
208 static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
209 u32 offset);
210 static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);
211 #endif
213 static void vortex_adbdma_startfifo(vortex_t * vortex, int adbdma);
214 //static void vortex_adbdma_stopfifo(vortex_t *vortex, int adbdma);
215 static void vortex_adbdma_pausefifo(vortex_t * vortex, int adbdma);
216 static void vortex_adbdma_resumefifo(vortex_t * vortex, int adbdma);
217 static int inline vortex_adbdma_getlinearpos(vortex_t * vortex, int adbdma);
218 static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma);
220 #ifndef CHIP_AU8810
221 static void vortex_wtdma_startfifo(vortex_t * vortex, int wtdma);
222 static void vortex_wtdma_stopfifo(vortex_t * vortex, int wtdma);
223 static void vortex_wtdma_pausefifo(vortex_t * vortex, int wtdma);
224 static void vortex_wtdma_resumefifo(vortex_t * vortex, int wtdma);
225 static int inline vortex_wtdma_getlinearpos(vortex_t * vortex, int wtdma);
226 #endif
228 /* global stuff. */
229 static void vortex_codec_init(vortex_t * vortex);
230 static void vortex_codec_write(struct snd_ac97 * codec, unsigned short addr,
231 unsigned short data);
232 static unsigned short vortex_codec_read(struct snd_ac97 * codec, unsigned short addr);
233 static void vortex_spdif_init(vortex_t * vortex, int spdif_sr, int spdif_mode);
235 static int vortex_core_init(vortex_t * card);
236 static int vortex_core_shutdown(vortex_t * card);
237 static void vortex_enable_int(vortex_t * card);
238 static irqreturn_t vortex_interrupt(int irq, void *dev_id);
239 static int vortex_alsafmt_aspfmt(int alsafmt);
241 /* Connection stuff. */
242 static void vortex_connect_default(vortex_t * vortex, int en);
243 static int vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch,
244 int dir, int type);
245 static char vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out,
246 int restype);
247 #ifndef CHIP_AU8810
248 static int vortex_wt_allocroute(vortex_t * vortex, int dma, int nr_ch);
249 static void vortex_wt_connect(vortex_t * vortex, int en);
250 static void vortex_wt_init(vortex_t * vortex);
251 #endif
253 static void vortex_route(vortex_t * vortex, int en, unsigned char channel,
254 unsigned char source, unsigned char dest);
255 #if 0
256 static void vortex_routes(vortex_t * vortex, int en, unsigned char channel,
257 unsigned char source, unsigned char dest0,
258 unsigned char dest1);
259 #endif
260 static void vortex_connection_mixin_mix(vortex_t * vortex, int en,
261 unsigned char mixin,
262 unsigned char mix, int a);
263 static void vortex_mix_setinputvolumebyte(vortex_t * vortex,
264 unsigned char mix, int mixin,
265 unsigned char vol);
266 static void vortex_mix_setvolumebyte(vortex_t * vortex, unsigned char mix,
267 unsigned char vol);
269 /* A3D functions. */
270 #ifndef CHIP_AU8820
271 static void vortex_Vort3D_enable(vortex_t * v);
272 static void vortex_Vort3D_disable(vortex_t * v);
273 static void vortex_Vort3D_connect(vortex_t * vortex, int en);
274 static void vortex_Vort3D_InitializeSource(a3dsrc_t * a, int en);
275 #endif
277 /* Driver stuff. */
278 static int vortex_gameport_register(vortex_t * card);
279 static void vortex_gameport_unregister(vortex_t * card);
280 #ifndef CHIP_AU8820
281 static int vortex_eq_init(vortex_t * vortex);
282 static int vortex_eq_free(vortex_t * vortex);
283 #endif
284 /* ALSA stuff. */
285 static int snd_vortex_new_pcm(vortex_t * vortex, int idx, int nr);
286 static int snd_vortex_mixer(vortex_t * vortex);
287 static int snd_vortex_midi(vortex_t * vortex);
288 #endif