[ARM] Support register switch in nommu mode
[linux-2.6/verdex.git] / sound / pci / au88x0 / au88x0.h
blobc2ad2674bea71402fd5814a44bd29f970af40247
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 <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/pci.h>
24 #include <asm/io.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/rawmidi.h>
28 #include <sound/mpu401.h>
29 #include <sound/hwdep.h>
30 #include <sound/ac97_codec.h>
32 #endif
34 #ifndef CHIP_AU8820
35 #include "au88x0_eq.h"
36 #include "au88x0_a3d.h"
37 #endif
38 #ifndef CHIP_AU8810
39 #include "au88x0_wt.h"
40 #endif
42 #define hwread(x,y) readl((x)+((y)>>2))
43 #define hwwrite(x,y,z) writel((z),(x)+((y)>>2))
45 /* Vortex MPU401 defines. */
46 #define MIDI_CLOCK_DIV 0x61
47 /* Standart MPU401 defines. */
48 #define MPU401_RESET 0xff
49 #define MPU401_ENTER_UART 0x3f
50 #define MPU401_ACK 0xfe
52 // Get src register value to convert from x to y.
53 #define SRC_RATIO(x,y) ((((x<<15)/y) + 1)/2)
55 /* FIFO software state constants. */
56 #define FIFO_STOP 0
57 #define FIFO_START 1
58 #define FIFO_PAUSE 2
60 /* IRQ flags */
61 #define IRQ_ERR_MASK 0x00ff
62 #define IRQ_FATAL 0x0001
63 #define IRQ_PARITY 0x0002
64 #define IRQ_REG 0x0004
65 #define IRQ_FIFO 0x0008
66 #define IRQ_DMA 0x0010
67 #define IRQ_PCMOUT 0x0020 /* PCM OUT page crossing */
68 #define IRQ_TIMER 0x1000
69 #define IRQ_MIDI 0x2000
70 #define IRQ_MODEM 0x4000
72 /* ADB Resource */
73 #define VORTEX_RESOURCE_DMA 0x00000000
74 #define VORTEX_RESOURCE_SRC 0x00000001
75 #define VORTEX_RESOURCE_MIXIN 0x00000002
76 #define VORTEX_RESOURCE_MIXOUT 0x00000003
77 #define VORTEX_RESOURCE_A3D 0x00000004
78 #define VORTEX_RESOURCE_LAST 0x00000005
80 /* codec io: VORTEX_CODEC_IO bits */
81 #define VORTEX_CODEC_ID_SHIFT 24
82 #define VORTEX_CODEC_WRITE 0x00800000
83 #define VORTEX_CODEC_ADDSHIFT 16
84 #define VORTEX_CODEC_ADDMASK 0x7f0000
85 #define VORTEX_CODEC_DATSHIFT 0
86 #define VORTEX_CODEC_DATMASK 0xffff
88 /* Check for SDAC bit in "Extended audio ID" AC97 register */
89 //#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80))
90 #define VORTEX_IS_QUAD(x) ((x)->isquad)
91 /* Check if chip has bug. */
92 #define IS_BAD_CHIP(x) (\
93 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_VORTEX_2) || \
94 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_ADVANTAGE))
97 /* PCM devices */
98 #define VORTEX_PCM_ADB 0
99 #define VORTEX_PCM_SPDIF 1
100 #define VORTEX_PCM_A3D 2
101 #define VORTEX_PCM_WT 3
102 #define VORTEX_PCM_I2S 4
103 #define VORTEX_PCM_LAST 5
105 #define MIX_CAPT(x) (vortex->mixcapt[x])
106 #define MIX_PLAYB(x) (vortex->mixplayb[x])
107 #define MIX_SPDIF(x) (vortex->mixspdif[x])
109 #define NR_WTPB 0x20 /* WT channels per eahc bank. */
111 /* Structs */
112 typedef struct {
113 //int this_08; /* Still unknown */
114 int fifo_enabled; /* this_24 */
115 int fifo_status; /* this_1c */
116 int dma_ctrl; /* this_78 (ADB), this_7c (WT) */
117 int dma_unknown; /* this_74 (ADB), this_78 (WT). WDM: +8 */
118 int cfg0;
119 int cfg1;
121 int nr_ch; /* Nr of PCM channels in use */
122 int type; /* Output type (ac97, a3d, spdif, i2s, dsp) */
123 int dma; /* Hardware DMA index. */
124 int dir; /* Stream Direction. */
125 u32 resources[5];
127 /* Virtual page extender stuff */
128 int nr_periods;
129 int period_bytes;
130 struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
131 int period_real;
132 int period_virt;
134 struct snd_pcm_substream *substream;
135 } stream_t;
137 typedef struct snd_vortex vortex_t;
138 struct snd_vortex {
139 /* ALSA structs. */
140 struct snd_card *card;
141 struct snd_pcm *pcm[VORTEX_PCM_LAST];
143 struct snd_rawmidi *rmidi; /* Legacy Midi interface. */
144 struct snd_ac97 *codec;
146 /* Stream structs. */
147 stream_t dma_adb[NR_ADB];
148 int spdif_sr;
149 #ifndef CHIP_AU8810
150 stream_t dma_wt[NR_WT];
151 wt_voice_t wt_voice[NR_WT]; /* WT register cache. */
152 char mixwt[(NR_WT / NR_WTPB) * 6]; /* WT mixin objects */
153 #endif
155 /* Global resources */
156 s8 mixcapt[2];
157 s8 mixplayb[4];
158 #ifndef CHIP_AU8820
159 s8 mixspdif[2];
160 s8 mixa3d[2]; /* mixers which collect all a3d streams. */
161 s8 mixxtlk[2]; /* crosstalk canceler mixer inputs. */
162 #endif
163 u32 fixed_res[5];
165 #ifndef CHIP_AU8820
166 /* Hardware equalizer structs */
167 eqlzr_t eq;
168 /* A3D structs */
169 a3dsrc_t a3d[NR_A3D];
170 /* Xtalk canceler */
171 int xt_mode; /* 1: speakers, 0:headphones. */
172 #endif
174 int isquad; /* cache of extended ID codec flag. */
176 /* Gameport stuff. */
177 struct gameport *gameport;
179 /* PCI hardware resources */
180 unsigned long io;
181 unsigned long __iomem *mmio;
182 unsigned int irq;
183 spinlock_t lock;
185 /* PCI device */
186 struct pci_dev *pci_dev;
187 u16 vendor;
188 u16 device;
189 u8 rev;
192 /* Functions. */
194 /* SRC */
195 static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
196 unsigned int cvrt, int dir);
198 /* DMA Engines. */
199 static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
200 struct snd_sg_buf * sgbuf, int size,
201 int count);
202 static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
203 int dir, int fmt, int d,
204 unsigned long offset);
205 static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
206 #ifndef CHIP_AU8810
207 static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
208 struct snd_sg_buf * sgbuf, int size,
209 int count);
210 static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
211 unsigned long offset);
212 static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);
213 #endif
215 static void vortex_adbdma_startfifo(vortex_t * vortex, int adbdma);
216 //static void vortex_adbdma_stopfifo(vortex_t *vortex, int adbdma);
217 static void vortex_adbdma_pausefifo(vortex_t * vortex, int adbdma);
218 static void vortex_adbdma_resumefifo(vortex_t * vortex, int adbdma);
219 static int inline vortex_adbdma_getlinearpos(vortex_t * vortex, int adbdma);
220 static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma);
222 #ifndef CHIP_AU8810
223 static void vortex_wtdma_startfifo(vortex_t * vortex, int wtdma);
224 static void vortex_wtdma_stopfifo(vortex_t * vortex, int wtdma);
225 static void vortex_wtdma_pausefifo(vortex_t * vortex, int wtdma);
226 static void vortex_wtdma_resumefifo(vortex_t * vortex, int wtdma);
227 static int inline vortex_wtdma_getlinearpos(vortex_t * vortex, int wtdma);
228 #endif
230 /* global stuff. */
231 static void vortex_codec_init(vortex_t * vortex);
232 static void vortex_codec_write(struct snd_ac97 * codec, unsigned short addr,
233 unsigned short data);
234 static unsigned short vortex_codec_read(struct snd_ac97 * codec, unsigned short addr);
235 static void vortex_spdif_init(vortex_t * vortex, int spdif_sr, int spdif_mode);
237 static int vortex_core_init(vortex_t * card);
238 static int vortex_core_shutdown(vortex_t * card);
239 static void vortex_enable_int(vortex_t * card);
240 static irqreturn_t vortex_interrupt(int irq, void *dev_id,
241 struct pt_regs *regs);
242 static int vortex_alsafmt_aspfmt(int alsafmt);
244 /* Connection stuff. */
245 static void vortex_connect_default(vortex_t * vortex, int en);
246 static int vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch,
247 int dir, int type);
248 static char vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out,
249 int restype);
250 #ifndef CHIP_AU8810
251 static int vortex_wt_allocroute(vortex_t * vortex, int dma, int nr_ch);
252 static void vortex_wt_connect(vortex_t * vortex, int en);
253 static void vortex_wt_init(vortex_t * vortex);
254 #endif
256 static void vortex_route(vortex_t * vortex, int en, unsigned char channel,
257 unsigned char source, unsigned char dest);
258 #if 0
259 static void vortex_routes(vortex_t * vortex, int en, unsigned char channel,
260 unsigned char source, unsigned char dest0,
261 unsigned char dest1);
262 #endif
263 static void vortex_connection_mixin_mix(vortex_t * vortex, int en,
264 unsigned char mixin,
265 unsigned char mix, int a);
266 static void vortex_mix_setinputvolumebyte(vortex_t * vortex,
267 unsigned char mix, int mixin,
268 unsigned char vol);
269 static void vortex_mix_setvolumebyte(vortex_t * vortex, unsigned char mix,
270 unsigned char vol);
272 /* A3D functions. */
273 #ifndef CHIP_AU8820
274 static void vortex_Vort3D(vortex_t * v, int en);
275 static void vortex_Vort3D_connect(vortex_t * vortex, int en);
276 static void vortex_Vort3D_InitializeSource(a3dsrc_t * a, int en);
277 #endif
279 /* Driver stuff. */
280 static int __devinit vortex_gameport_register(vortex_t * card);
281 static void vortex_gameport_unregister(vortex_t * card);
282 #ifndef CHIP_AU8820
283 static int __devinit vortex_eq_init(vortex_t * vortex);
284 static int __devexit vortex_eq_free(vortex_t * vortex);
285 #endif
286 /* ALSA stuff. */
287 static int __devinit snd_vortex_new_pcm(vortex_t * vortex, int idx, int nr);
288 static int __devinit snd_vortex_mixer(vortex_t * vortex);
289 static int __devinit snd_vortex_midi(vortex_t * vortex);
290 #endif