trident.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. #ifndef __SOUND_TRIDENT_H
  2. #define __SOUND_TRIDENT_H
  3. /*
  4. * audio@tridentmicro.com
  5. * Fri Feb 19 15:55:28 MST 1999
  6. * Definitions for Trident 4DWave DX/NX chips
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/pcm.h>
  25. #include <sound/mpu401.h>
  26. #include <sound/ac97_codec.h>
  27. #include <sound/util_mem.h>
  28. #define TRIDENT_DEVICE_ID_DX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_DX)
  29. #define TRIDENT_DEVICE_ID_NX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_NX)
  30. #define TRIDENT_DEVICE_ID_SI7018 ((PCI_VENDOR_ID_SI<<16)|PCI_DEVICE_ID_SI_7018)
  31. #define SNDRV_TRIDENT_VOICE_TYPE_PCM 0
  32. #define SNDRV_TRIDENT_VOICE_TYPE_SYNTH 1
  33. #define SNDRV_TRIDENT_VOICE_TYPE_MIDI 2
  34. #define SNDRV_TRIDENT_VFLG_RUNNING (1<<0)
  35. /* TLB code constants */
  36. #define SNDRV_TRIDENT_PAGE_SIZE 4096
  37. #define SNDRV_TRIDENT_PAGE_SHIFT 12
  38. #define SNDRV_TRIDENT_PAGE_MASK ((1<<SNDRV_TRIDENT_PAGE_SHIFT)-1)
  39. #define SNDRV_TRIDENT_MAX_PAGES 4096
  40. /*
  41. * Direct registers
  42. */
  43. #define TRID_REG(trident, x) ((trident)->port + (x))
  44. #define ID_4DWAVE_DX 0x2000
  45. #define ID_4DWAVE_NX 0x2001
  46. /* Bank definitions */
  47. #define T4D_BANK_A 0
  48. #define T4D_BANK_B 1
  49. #define T4D_NUM_BANKS 2
  50. /* Register definitions */
  51. /* Global registers */
  52. enum global_control_bits {
  53. CHANNEL_IDX = 0x0000003f,
  54. OVERRUN_IE = 0x00000400, /* interrupt enable: capture overrun */
  55. UNDERRUN_IE = 0x00000800, /* interrupt enable: playback underrun */
  56. ENDLP_IE = 0x00001000, /* interrupt enable: end of buffer */
  57. MIDLP_IE = 0x00002000, /* interrupt enable: middle buffer */
  58. ETOG_IE = 0x00004000, /* interrupt enable: envelope toggling */
  59. EDROP_IE = 0x00008000, /* interrupt enable: envelope drop */
  60. BANK_B_EN = 0x00010000, /* SiS: enable bank B (64 channels) */
  61. PCMIN_B_MIX = 0x00020000, /* SiS: PCM IN B mixing enable */
  62. I2S_OUT_ASSIGN = 0x00040000, /* SiS: I2S Out contains surround PCM */
  63. SPDIF_OUT_ASSIGN= 0x00080000, /* SiS: 0=S/PDIF L/R | 1=PCM Out FIFO */
  64. MAIN_OUT_ASSIGN = 0x00100000, /* SiS: 0=PCM Out FIFO | 1=MMC Out buffer */
  65. };
  66. enum miscint_bits {
  67. PB_UNDERRUN_IRQ = 0x00000001, REC_OVERRUN_IRQ = 0x00000002,
  68. SB_IRQ = 0x00000004, MPU401_IRQ = 0x00000008,
  69. OPL3_IRQ = 0x00000010, ADDRESS_IRQ = 0x00000020,
  70. ENVELOPE_IRQ = 0x00000040, PB_UNDERRUN = 0x00000100,
  71. REC_OVERRUN = 0x00000200, MIXER_UNDERFLOW = 0x00000400,
  72. MIXER_OVERFLOW = 0x00000800, NX_SB_IRQ_DISABLE = 0x00001000,
  73. ST_TARGET_REACHED = 0x00008000,
  74. PB_24K_MODE = 0x00010000, ST_IRQ_EN = 0x00800000,
  75. ACGPIO_IRQ = 0x01000000
  76. };
  77. /* T2 legacy dma control registers. */
  78. #define LEGACY_DMAR0 0x00 // ADR0
  79. #define LEGACY_DMAR4 0x04 // CNT0
  80. #define LEGACY_DMAR6 0x06 // CNT0 - High bits
  81. #define LEGACY_DMAR11 0x0b // MOD
  82. #define LEGACY_DMAR15 0x0f // MMR
  83. #define T4D_START_A 0x80
  84. #define T4D_STOP_A 0x84
  85. #define T4D_DLY_A 0x88
  86. #define T4D_SIGN_CSO_A 0x8c
  87. #define T4D_CSPF_A 0x90
  88. #define T4D_CSPF_B 0xbc
  89. #define T4D_CEBC_A 0x94
  90. #define T4D_AINT_A 0x98
  91. #define T4D_AINTEN_A 0x9c
  92. #define T4D_LFO_GC_CIR 0xa0
  93. #define T4D_MUSICVOL_WAVEVOL 0xa8
  94. #define T4D_SBDELTA_DELTA_R 0xac
  95. #define T4D_MISCINT 0xb0
  96. #define T4D_START_B 0xb4
  97. #define T4D_STOP_B 0xb8
  98. #define T4D_SBBL_SBCL 0xc0
  99. #define T4D_SBCTRL_SBE2R_SBDD 0xc4
  100. #define T4D_STIMER 0xc8
  101. #define T4D_AINT_B 0xd8
  102. #define T4D_AINTEN_B 0xdc
  103. #define T4D_RCI 0x70
  104. /* MPU-401 UART */
  105. #define T4D_MPU401_BASE 0x20
  106. #define T4D_MPUR0 0x20
  107. #define T4D_MPUR1 0x21
  108. #define T4D_MPUR2 0x22
  109. #define T4D_MPUR3 0x23
  110. /* S/PDIF Registers */
  111. #define NX_SPCTRL_SPCSO 0x24
  112. #define NX_SPLBA 0x28
  113. #define NX_SPESO 0x2c
  114. #define NX_SPCSTATUS 0x64
  115. /* Joystick */
  116. #define GAMEPORT_GCR 0x30
  117. #define GAMEPORT_MODE_ADC 0x80
  118. #define GAMEPORT_LEGACY 0x31
  119. #define GAMEPORT_AXES 0x34
  120. /* NX Specific Registers */
  121. #define NX_TLBC 0x6c
  122. /* Channel Registers */
  123. #define CH_START 0xe0
  124. #define CH_DX_CSO_ALPHA_FMS 0xe0
  125. #define CH_DX_ESO_DELTA 0xe8
  126. #define CH_DX_FMC_RVOL_CVOL 0xec
  127. #define CH_NX_DELTA_CSO 0xe0
  128. #define CH_NX_DELTA_ESO 0xe8
  129. #define CH_NX_ALPHA_FMS_FMC_RVOL_CVOL 0xec
  130. #define CH_LBA 0xe4
  131. #define CH_GVSEL_PAN_VOL_CTRL_EC 0xf0
  132. #define CH_EBUF1 0xf4
  133. #define CH_EBUF2 0xf8
  134. /* AC-97 Registers */
  135. #define DX_ACR0_AC97_W 0x40
  136. #define DX_ACR1_AC97_R 0x44
  137. #define DX_ACR2_AC97_COM_STAT 0x48
  138. #define NX_ACR0_AC97_COM_STAT 0x40
  139. #define NX_ACR1_AC97_W 0x44
  140. #define NX_ACR2_AC97_R_PRIMARY 0x48
  141. #define NX_ACR3_AC97_R_SECONDARY 0x4c
  142. #define SI_AC97_WRITE 0x40
  143. #define SI_AC97_READ 0x44
  144. #define SI_SERIAL_INTF_CTRL 0x48
  145. #define SI_AC97_GPIO 0x4c
  146. #define SI_ASR0 0x50
  147. #define SI_SPDIF_CS 0x70
  148. #define SI_GPIO 0x7c
  149. enum trident_nx_ac97_bits {
  150. /* ACR1-3 */
  151. NX_AC97_BUSY_WRITE = 0x0800,
  152. NX_AC97_BUSY_READ = 0x0800,
  153. NX_AC97_BUSY_DATA = 0x0400,
  154. NX_AC97_WRITE_SECONDARY = 0x0100,
  155. /* ACR0 */
  156. NX_AC97_SECONDARY_READY = 0x0040,
  157. NX_AC97_SECONDARY_RECORD = 0x0020,
  158. NX_AC97_SURROUND_OUTPUT = 0x0010,
  159. NX_AC97_PRIMARY_READY = 0x0008,
  160. NX_AC97_PRIMARY_RECORD = 0x0004,
  161. NX_AC97_PCM_OUTPUT = 0x0002,
  162. NX_AC97_WARM_RESET = 0x0001
  163. };
  164. enum trident_dx_ac97_bits {
  165. DX_AC97_BUSY_WRITE = 0x8000,
  166. DX_AC97_BUSY_READ = 0x8000,
  167. DX_AC97_READY = 0x0010,
  168. DX_AC97_RECORD = 0x0008,
  169. DX_AC97_PLAYBACK = 0x0002
  170. };
  171. enum sis7018_ac97_bits {
  172. SI_AC97_BUSY_WRITE = 0x00008000,
  173. SI_AC97_AUDIO_BUSY = 0x00004000,
  174. SI_AC97_MODEM_BUSY = 0x00002000,
  175. SI_AC97_BUSY_READ = 0x00008000,
  176. SI_AC97_SECONDARY = 0x00000080,
  177. };
  178. enum serial_intf_ctrl_bits {
  179. WARM_RESET = 0x00000001,
  180. COLD_RESET = 0x00000002,
  181. I2S_CLOCK = 0x00000004,
  182. PCM_SEC_AC97 = 0x00000008,
  183. AC97_DBL_RATE = 0x00000010,
  184. SPDIF_EN = 0x00000020,
  185. I2S_OUTPUT_EN = 0x00000040,
  186. I2S_INPUT_EN = 0x00000080,
  187. PCMIN = 0x00000100,
  188. LINE1IN = 0x00000200,
  189. MICIN = 0x00000400,
  190. LINE2IN = 0x00000800,
  191. HEAD_SET_IN = 0x00001000,
  192. GPIOIN = 0x00002000,
  193. /* 7018 spec says id = 01 but the demo board routed to 10
  194. SECONDARY_ID= 0x00004000, */
  195. SECONDARY_ID = 0x00004000,
  196. PCMOUT = 0x00010000,
  197. SURROUT = 0x00020000,
  198. CENTEROUT = 0x00040000,
  199. LFEOUT = 0x00080000,
  200. LINE1OUT = 0x00100000,
  201. LINE2OUT = 0x00200000,
  202. GPIOOUT = 0x00400000,
  203. SI_AC97_PRIMARY_READY = 0x01000000,
  204. SI_AC97_SECONDARY_READY = 0x02000000,
  205. SI_AC97_POWERDOWN = 0x04000000,
  206. };
  207. /* PCM defaults */
  208. #define T4D_DEFAULT_PCM_VOL 10 /* 0 - 255 */
  209. #define T4D_DEFAULT_PCM_PAN 0 /* 0 - 127 */
  210. #define T4D_DEFAULT_PCM_RVOL 127 /* 0 - 127 */
  211. #define T4D_DEFAULT_PCM_CVOL 127 /* 0 - 127 */
  212. struct snd_trident;
  213. struct snd_trident_voice;
  214. struct snd_trident_pcm_mixer;
  215. struct snd_trident_port {
  216. struct snd_midi_channel_set * chset;
  217. struct snd_trident * trident;
  218. int mode; /* operation mode */
  219. int client; /* sequencer client number */
  220. int port; /* sequencer port number */
  221. unsigned int midi_has_voices: 1;
  222. };
  223. struct snd_trident_memblk_arg {
  224. short first_page, last_page;
  225. };
  226. struct snd_trident_tlb {
  227. unsigned int * entries; /* 16k-aligned TLB table */
  228. dma_addr_t entries_dmaaddr; /* 16k-aligned PCI address to TLB table */
  229. unsigned long * shadow_entries; /* shadow entries with virtual addresses */
  230. struct snd_dma_buffer buffer;
  231. struct snd_util_memhdr * memhdr; /* page allocation list */
  232. struct snd_dma_buffer silent_page;
  233. };
  234. struct snd_trident_voice {
  235. unsigned int number;
  236. unsigned int use: 1,
  237. pcm: 1,
  238. synth:1,
  239. midi: 1;
  240. unsigned int flags;
  241. unsigned char client;
  242. unsigned char port;
  243. unsigned char index;
  244. struct snd_trident_sample_ops *sample_ops;
  245. /* channel parameters */
  246. unsigned int CSO; /* 24 bits (16 on DX) */
  247. unsigned int ESO; /* 24 bits (16 on DX) */
  248. unsigned int LBA; /* 30 bits */
  249. unsigned short EC; /* 12 bits */
  250. unsigned short Alpha; /* 12 bits */
  251. unsigned short Delta; /* 16 bits */
  252. unsigned short Attribute; /* 16 bits - SiS 7018 */
  253. unsigned short Vol; /* 12 bits (6.6) */
  254. unsigned char Pan; /* 7 bits (1.4.2) */
  255. unsigned char GVSel; /* 1 bit */
  256. unsigned char RVol; /* 7 bits (5.2) */
  257. unsigned char CVol; /* 7 bits (5.2) */
  258. unsigned char FMC; /* 2 bits */
  259. unsigned char CTRL; /* 4 bits */
  260. unsigned char FMS; /* 4 bits */
  261. unsigned char LFO; /* 8 bits */
  262. unsigned int negCSO; /* nonzero - use negative CSO */
  263. struct snd_util_memblk *memblk; /* memory block if TLB enabled */
  264. /* PCM data */
  265. struct snd_trident *trident;
  266. struct snd_pcm_substream *substream;
  267. struct snd_trident_voice *extra; /* extra PCM voice (acts as interrupt generator) */
  268. unsigned int running: 1,
  269. capture: 1,
  270. spdif: 1,
  271. foldback: 1,
  272. isync: 1,
  273. isync2: 1,
  274. isync3: 1;
  275. int foldback_chan; /* foldback subdevice number */
  276. unsigned int stimer; /* global sample timer (to detect spurious interrupts) */
  277. unsigned int spurious_threshold; /* spurious threshold */
  278. unsigned int isync_mark;
  279. unsigned int isync_max;
  280. unsigned int isync_ESO;
  281. /* --- */
  282. void *private_data;
  283. void (*private_free)(struct snd_trident_voice *voice);
  284. };
  285. struct snd_4dwave {
  286. int seq_client;
  287. struct snd_trident_port seq_ports[4];
  288. struct snd_trident_voice voices[64];
  289. int ChanSynthCount; /* number of allocated synth channels */
  290. int max_size; /* maximum synth memory size in bytes */
  291. int current_size; /* current allocated synth mem in bytes */
  292. };
  293. struct snd_trident_pcm_mixer {
  294. struct snd_trident_voice *voice; /* active voice */
  295. unsigned short vol; /* front volume */
  296. unsigned char pan; /* pan control */
  297. unsigned char rvol; /* rear volume */
  298. unsigned char cvol; /* center volume */
  299. unsigned char pad;
  300. };
  301. struct snd_trident {
  302. int irq;
  303. unsigned int device; /* device ID */
  304. unsigned char bDMAStart;
  305. unsigned long port;
  306. unsigned long midi_port;
  307. unsigned int spurious_irq_count;
  308. unsigned int spurious_irq_max_delta;
  309. struct snd_trident_tlb tlb; /* TLB entries for NX cards */
  310. unsigned char spdif_ctrl;
  311. unsigned char spdif_pcm_ctrl;
  312. unsigned int spdif_bits;
  313. unsigned int spdif_pcm_bits;
  314. struct snd_kcontrol *spdif_pcm_ctl; /* S/PDIF settings */
  315. unsigned int ac97_ctrl;
  316. unsigned int ChanMap[2]; /* allocation map for hardware channels */
  317. int ChanPCM; /* max number of PCM channels */
  318. int ChanPCMcnt; /* actual number of PCM channels */
  319. unsigned int ac97_detect: 1; /* 1 = AC97 in detection phase */
  320. unsigned int in_suspend: 1; /* 1 during suspend/resume */
  321. struct snd_4dwave synth; /* synth specific variables */
  322. spinlock_t event_lock;
  323. spinlock_t voice_alloc;
  324. struct snd_dma_device dma_dev;
  325. struct pci_dev *pci;
  326. struct snd_card *card;
  327. struct snd_pcm *pcm; /* ADC/DAC PCM */
  328. struct snd_pcm *foldback; /* Foldback PCM */
  329. struct snd_pcm *spdif; /* SPDIF PCM */
  330. struct snd_rawmidi *rmidi;
  331. struct snd_ac97_bus *ac97_bus;
  332. struct snd_ac97 *ac97;
  333. struct snd_ac97 *ac97_sec;
  334. unsigned int musicvol_wavevol;
  335. struct snd_trident_pcm_mixer pcm_mixer[32];
  336. struct snd_kcontrol *ctl_vol; /* front volume */
  337. struct snd_kcontrol *ctl_pan; /* pan */
  338. struct snd_kcontrol *ctl_rvol; /* rear volume */
  339. struct snd_kcontrol *ctl_cvol; /* center volume */
  340. spinlock_t reg_lock;
  341. struct gameport *gameport;
  342. };
  343. int snd_trident_create(struct snd_card *card,
  344. struct pci_dev *pci,
  345. int pcm_streams,
  346. int pcm_spdif_device,
  347. int max_wavetable_size,
  348. struct snd_trident ** rtrident);
  349. int snd_trident_create_gameport(struct snd_trident *trident);
  350. int snd_trident_pcm(struct snd_trident *trident, int device);
  351. int snd_trident_foldback_pcm(struct snd_trident *trident, int device);
  352. int snd_trident_spdif_pcm(struct snd_trident *trident, int device);
  353. int snd_trident_attach_synthesizer(struct snd_trident * trident);
  354. struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type,
  355. int client, int port);
  356. void snd_trident_free_voice(struct snd_trident * trident, struct snd_trident_voice *voice);
  357. void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice);
  358. void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice);
  359. void snd_trident_write_voice_regs(struct snd_trident * trident, struct snd_trident_voice *voice);
  360. extern const struct dev_pm_ops snd_trident_pm;
  361. /* TLB memory allocation */
  362. struct snd_util_memblk *snd_trident_alloc_pages(struct snd_trident *trident,
  363. struct snd_pcm_substream *substream);
  364. int snd_trident_free_pages(struct snd_trident *trident, struct snd_util_memblk *blk);
  365. struct snd_util_memblk *snd_trident_synth_alloc(struct snd_trident *trident, unsigned int size);
  366. int snd_trident_synth_free(struct snd_trident *trident, struct snd_util_memblk *blk);
  367. int snd_trident_synth_copy_from_user(struct snd_trident *trident, struct snd_util_memblk *blk,
  368. int offset, const char __user *data, int size);
  369. #endif /* __SOUND_TRIDENT_H */