au88x0.h 8.2 KB

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