au88x0.h 8.7 KB

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