trident.h 13 KB

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