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