au88x0.h 9.0 KB

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