trident.h 15 KB

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