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