trident.h 15 KB

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