blob: f078b716d2b05e2b06f7180437cf465ac7b2e80b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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#ifdef __KERNEL__
21#include <sound/driver.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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#endif
32
33#ifndef CHIP_AU8820
34#include "au88x0_eq.h"
35#include "au88x0_a3d.h"
36#endif
37#ifndef CHIP_AU8810
38#include "au88x0_wt.h"
39#endif
40
Takashi Iwai97c67b62006-01-13 17:16:29 +010041#define hwread(x,y) readl((x)+(y))
42#define hwwrite(x,y,z) writel((z),(x)+(y))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
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
Sasha Khapyorskyf2b31732005-09-16 19:22:44 +020079/* codec io: VORTEX_CODEC_IO bits */
80#define VORTEX_CODEC_ID_SHIFT 24
81#define VORTEX_CODEC_WRITE 0x00800000
82#define VORTEX_CODEC_ADDSHIFT 16
83#define VORTEX_CODEC_ADDMASK 0x7f0000
84#define VORTEX_CODEC_DATSHIFT 0
85#define VORTEX_CODEC_DATMASK 0xffff
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/* Check for SDAC bit in "Extended audio ID" AC97 register */
88//#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80))
89#define VORTEX_IS_QUAD(x) ((x)->isquad)
90/* Check if chip has bug. */
91#define IS_BAD_CHIP(x) (\
92 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_VORTEX_2) || \
93 (x->rev == 0xfe && x->device == PCI_DEVICE_ID_AUREAL_ADVANTAGE))
94
95
96/* PCM devices */
97#define VORTEX_PCM_ADB 0
98#define VORTEX_PCM_SPDIF 1
99#define VORTEX_PCM_A3D 2
100#define VORTEX_PCM_WT 3
101#define VORTEX_PCM_I2S 4
102#define VORTEX_PCM_LAST 5
103
104#define MIX_CAPT(x) (vortex->mixcapt[x])
105#define MIX_PLAYB(x) (vortex->mixplayb[x])
106#define MIX_SPDIF(x) (vortex->mixspdif[x])
107
108#define NR_WTPB 0x20 /* WT channels per eahc bank. */
109
110/* Structs */
111typedef struct {
112 //int this_08; /* Still unknown */
113 int fifo_enabled; /* this_24 */
114 int fifo_status; /* this_1c */
Takashi Iwai97c67b62006-01-13 17:16:29 +0100115 u32 dma_ctrl; /* this_78 (ADB), this_7c (WT) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 int dma_unknown; /* this_74 (ADB), this_78 (WT). WDM: +8 */
117 int cfg0;
118 int cfg1;
119
120 int nr_ch; /* Nr of PCM channels in use */
121 int type; /* Output type (ac97, a3d, spdif, i2s, dsp) */
122 int dma; /* Hardware DMA index. */
123 int dir; /* Stream Direction. */
124 u32 resources[5];
125
126 /* Virtual page extender stuff */
127 int nr_periods;
128 int period_bytes;
Takashi Iwai2fd16872005-11-17 14:55:19 +0100129 struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 int period_real;
131 int period_virt;
132
Takashi Iwai2fd16872005-11-17 14:55:19 +0100133 struct snd_pcm_substream *substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134} stream_t;
135
136typedef struct snd_vortex vortex_t;
137struct snd_vortex {
138 /* ALSA structs. */
Takashi Iwai2fd16872005-11-17 14:55:19 +0100139 struct snd_card *card;
140 struct snd_pcm *pcm[VORTEX_PCM_LAST];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Takashi Iwai2fd16872005-11-17 14:55:19 +0100142 struct snd_rawmidi *rmidi; /* Legacy Midi interface. */
143 struct snd_ac97 *codec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* Stream structs. */
146 stream_t dma_adb[NR_ADB];
147 int spdif_sr;
148#ifndef CHIP_AU8810
149 stream_t dma_wt[NR_WT];
150 wt_voice_t wt_voice[NR_WT]; /* WT register cache. */
151 char mixwt[(NR_WT / NR_WTPB) * 6]; /* WT mixin objects */
152#endif
153
154 /* Global resources */
155 s8 mixcapt[2];
156 s8 mixplayb[4];
157#ifndef CHIP_AU8820
158 s8 mixspdif[2];
159 s8 mixa3d[2]; /* mixers which collect all a3d streams. */
160 s8 mixxtlk[2]; /* crosstalk canceler mixer inputs. */
161#endif
162 u32 fixed_res[5];
163
164#ifndef CHIP_AU8820
165 /* Hardware equalizer structs */
166 eqlzr_t eq;
167 /* A3D structs */
168 a3dsrc_t a3d[NR_A3D];
169 /* Xtalk canceler */
170 int xt_mode; /* 1: speakers, 0:headphones. */
171#endif
172
173 int isquad; /* cache of extended ID codec flag. */
174
175 /* Gameport stuff. */
176 struct gameport *gameport;
177
178 /* PCI hardware resources */
179 unsigned long io;
Takashi Iwai97c67b62006-01-13 17:16:29 +0100180 void __iomem *mmio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 unsigned int irq;
182 spinlock_t lock;
183
184 /* PCI device */
185 struct pci_dev *pci_dev;
186 u16 vendor;
187 u16 device;
188 u8 rev;
189};
190
191/* Functions. */
192
193/* SRC */
194static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
195 unsigned int cvrt, int dir);
196
197/* DMA Engines. */
198static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
Takashi Iwai2fd16872005-11-17 14:55:19 +0100199 struct snd_sg_buf * sgbuf, int size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 int count);
201static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
202 int dir, int fmt, int d,
Takashi Iwai97c67b62006-01-13 17:16:29 +0100203 u32 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
205#ifndef CHIP_AU8810
206static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
Takashi Iwai2fd16872005-11-17 14:55:19 +0100207 struct snd_sg_buf * sgbuf, int size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 int count);
209static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
Takashi Iwai97c67b62006-01-13 17:16:29 +0100210 u32 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);
212#endif
213
214static void vortex_adbdma_startfifo(vortex_t * vortex, int adbdma);
215//static void vortex_adbdma_stopfifo(vortex_t *vortex, int adbdma);
216static void vortex_adbdma_pausefifo(vortex_t * vortex, int adbdma);
217static void vortex_adbdma_resumefifo(vortex_t * vortex, int adbdma);
218static int inline vortex_adbdma_getlinearpos(vortex_t * vortex, int adbdma);
219static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma);
220
221#ifndef CHIP_AU8810
222static void vortex_wtdma_startfifo(vortex_t * vortex, int wtdma);
223static void vortex_wtdma_stopfifo(vortex_t * vortex, int wtdma);
224static void vortex_wtdma_pausefifo(vortex_t * vortex, int wtdma);
225static void vortex_wtdma_resumefifo(vortex_t * vortex, int wtdma);
226static int inline vortex_wtdma_getlinearpos(vortex_t * vortex, int wtdma);
227#endif
228
229/* global stuff. */
230static void vortex_codec_init(vortex_t * vortex);
Takashi Iwai2fd16872005-11-17 14:55:19 +0100231static void vortex_codec_write(struct snd_ac97 * codec, unsigned short addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 unsigned short data);
Takashi Iwai2fd16872005-11-17 14:55:19 +0100233static unsigned short vortex_codec_read(struct snd_ac97 * codec, unsigned short addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static void vortex_spdif_init(vortex_t * vortex, int spdif_sr, int spdif_mode);
235
236static int vortex_core_init(vortex_t * card);
237static int vortex_core_shutdown(vortex_t * card);
238static void vortex_enable_int(vortex_t * card);
239static irqreturn_t vortex_interrupt(int irq, void *dev_id,
240 struct pt_regs *regs);
241static int vortex_alsafmt_aspfmt(int alsafmt);
242
243/* Connection stuff. */
244static void vortex_connect_default(vortex_t * vortex, int en);
245static int vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch,
246 int dir, int type);
247static char vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out,
248 int restype);
249#ifndef CHIP_AU8810
250static int vortex_wt_allocroute(vortex_t * vortex, int dma, int nr_ch);
251static void vortex_wt_connect(vortex_t * vortex, int en);
252static void vortex_wt_init(vortex_t * vortex);
253#endif
254
255static void vortex_route(vortex_t * vortex, int en, unsigned char channel,
256 unsigned char source, unsigned char dest);
257#if 0
258static void vortex_routes(vortex_t * vortex, int en, unsigned char channel,
259 unsigned char source, unsigned char dest0,
260 unsigned char dest1);
261#endif
262static void vortex_connection_mixin_mix(vortex_t * vortex, int en,
263 unsigned char mixin,
264 unsigned char mix, int a);
265static void vortex_mix_setinputvolumebyte(vortex_t * vortex,
266 unsigned char mix, int mixin,
267 unsigned char vol);
268static void vortex_mix_setvolumebyte(vortex_t * vortex, unsigned char mix,
269 unsigned char vol);
270
271/* A3D functions. */
272#ifndef CHIP_AU8820
273static void vortex_Vort3D(vortex_t * v, int en);
274static void vortex_Vort3D_connect(vortex_t * vortex, int en);
275static void vortex_Vort3D_InitializeSource(a3dsrc_t * a, int en);
276#endif
277
278/* Driver stuff. */
Dale Sedivec99e80e42006-04-10 11:34:44 +0200279static int vortex_gameport_register(vortex_t * card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static void vortex_gameport_unregister(vortex_t * card);
281#ifndef CHIP_AU8820
Dale Sedivec99e80e42006-04-10 11:34:44 +0200282static int vortex_eq_init(vortex_t * vortex);
283static int vortex_eq_free(vortex_t * vortex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285/* ALSA stuff. */
Dale Sedivec99e80e42006-04-10 11:34:44 +0200286static int snd_vortex_new_pcm(vortex_t * vortex, int idx, int nr);
287static int snd_vortex_mixer(vortex_t * vortex);
288static int snd_vortex_midi(vortex_t * vortex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#endif