azt3328.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #ifndef __SOUND_AZT3328_H
  2. #define __SOUND_AZT3328_H
  3. /* "PU" == "power-up value", as tested on PCI168 PCI rev. 10
  4. * "WRITE_ONLY" == register does not indicate actual bit values */
  5. /*** main I/O area port indices ***/
  6. /* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */
  7. #define AZF_IO_SIZE_CODEC 0x80
  8. #define AZF_IO_SIZE_CODEC_PM 0x70
  9. /* the driver initialisation suggests a layout of 4 main areas:
  10. * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe MPU401??).
  11. * And another area from 0x60 to 0x6f (DirectX timer, IRQ management,
  12. * power management etc.???). */
  13. /** playback area **/
  14. #define IDX_IO_PLAY_FLAGS 0x00 /* PU:0x0000 */
  15. /* able to reactivate output after output muting due to 8/16bit
  16. * output change, just like 0x0002.
  17. * 0x0001 is the only bit that's able to start the DMA counter */
  18. #define DMA_RESUME 0x0001 /* paused if cleared ? */
  19. /* 0x0002 *temporarily* set during DMA stopping. hmm
  20. * both 0x0002 and 0x0004 set in playback setup. */
  21. /* able to reactivate output after output muting due to 8/16bit
  22. * output change, just like 0x0001. */
  23. #define DMA_PLAY_SOMETHING1 0x0002 /* \ alternated (toggled) */
  24. /* 0x0004: NOT able to reactivate output */
  25. #define DMA_PLAY_SOMETHING2 0x0004 /* / bits */
  26. #define SOMETHING_ALMOST_ALWAYS_SET 0x0008 /* ???; can be modified */
  27. #define DMA_EPILOGUE_SOMETHING 0x0010
  28. #define DMA_SOMETHING_ELSE 0x0020 /* ??? */
  29. #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */
  30. #define IDX_IO_PLAY_IRQTYPE 0x02 /* PU:0x0001 */
  31. /* write back to flags in case flags are set, in order to ACK IRQ in handler
  32. * (bit 1 of port 0x64 indicates interrupt for one of these three types)
  33. * sometimes in this case it just writes 0xffff to globally ACK all IRQs
  34. * settings written are not reflected when reading back, though.
  35. * seems to be IRQ, too (frequently used: port |= 0x07 !), but who knows ? */
  36. #define IRQ_PLAY_SOMETHING 0x0001 /* something & ACK */
  37. #define IRQ_FINISHED_PLAYBUF_1 0x0002 /* 1st dmabuf finished & ACK */
  38. #define IRQ_FINISHED_PLAYBUF_2 0x0004 /* 2nd dmabuf finished & ACK */
  39. #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
  40. #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
  41. #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */
  42. #define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area, PU:0x00000000 */
  43. #define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area, PU:0x00000000 */
  44. #define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area, PU:0x0000 */
  45. #define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area, PU:0x0000 */
  46. #define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */
  47. #define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area, PU:0x0000 */
  48. #define IDX_IO_PLAY_SOUNDFORMAT 0x16 /* PU:0x0010 */
  49. /* all unspecified bits can't be modified */
  50. #define SOUNDFORMAT_FREQUENCY_MASK 0x000f
  51. #define SOUNDFORMAT_XTAL1 0x00
  52. #define SOUNDFORMAT_XTAL2 0x01
  53. /* all _SUSPECTED_ values are not used by Windows drivers, so we don't
  54. * have any hard facts, only rough measurements.
  55. * All we know is that the crystal used on the board has 24.576MHz,
  56. * like many soundcards (which results in the frequencies below when
  57. * using certain divider values selected by the values below) */
  58. #define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c | SOUNDFORMAT_XTAL1
  59. #define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a | SOUNDFORMAT_XTAL1
  60. #define SOUNDFORMAT_FREQ_5510 0x0c | SOUNDFORMAT_XTAL2
  61. #define SOUNDFORMAT_FREQ_6620 0x0a | SOUNDFORMAT_XTAL2
  62. #define SOUNDFORMAT_FREQ_8000 0x00 | SOUNDFORMAT_XTAL1 /* also 0x0e | SOUNDFORMAT_XTAL1? */
  63. #define SOUNDFORMAT_FREQ_9600 0x08 | SOUNDFORMAT_XTAL1
  64. #define SOUNDFORMAT_FREQ_11025 0x00 | SOUNDFORMAT_XTAL2 /* also 0x0e | SOUNDFORMAT_XTAL2? */
  65. #define SOUNDFORMAT_FREQ_SUSPECTED_13240 0x08 | SOUNDFORMAT_XTAL2 /* seems to be 6620 *2 */
  66. #define SOUNDFORMAT_FREQ_16000 0x02 | SOUNDFORMAT_XTAL1
  67. #define SOUNDFORMAT_FREQ_22050 0x02 | SOUNDFORMAT_XTAL2
  68. #define SOUNDFORMAT_FREQ_32000 0x04 | SOUNDFORMAT_XTAL1
  69. #define SOUNDFORMAT_FREQ_44100 0x04 | SOUNDFORMAT_XTAL2
  70. #define SOUNDFORMAT_FREQ_48000 0x06 | SOUNDFORMAT_XTAL1
  71. #define SOUNDFORMAT_FREQ_SUSPECTED_66200 0x06 | SOUNDFORMAT_XTAL2 /* 66200 (13240 * 5); 64000 may have been nicer :-\ */
  72. #define SOUNDFORMAT_FLAG_16BIT 0x0010
  73. #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020
  74. /* define frequency helpers, for maximum value safety */
  75. enum azf_freq_t {
  76. #define AZF_FREQ(rate) AZF_FREQ_##rate = rate
  77. AZF_FREQ(4000),
  78. AZF_FREQ(4800),
  79. AZF_FREQ(5512),
  80. AZF_FREQ(6620),
  81. AZF_FREQ(8000),
  82. AZF_FREQ(9600),
  83. AZF_FREQ(11025),
  84. AZF_FREQ(13240),
  85. AZF_FREQ(16000),
  86. AZF_FREQ(22050),
  87. AZF_FREQ(32000),
  88. AZF_FREQ(44100),
  89. AZF_FREQ(48000),
  90. AZF_FREQ(66200),
  91. #undef AZF_FREQ
  92. };
  93. /** recording area (see also: playback bit flag definitions) **/
  94. #define IDX_IO_REC_FLAGS 0x20 /* ??, PU:0x0000 */
  95. #define IDX_IO_REC_IRQTYPE 0x22 /* ??, PU:0x0000 */
  96. #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */
  97. #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */
  98. #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */
  99. /* hmm, maybe these are just the corresponding *recording* flags ?
  100. * but OTOH they are most likely at port 0x22 instead */
  101. #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
  102. #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
  103. #define IDX_IO_REC_DMA_START_1 0x24 /* PU:0x00000000 */
  104. #define IDX_IO_REC_DMA_START_2 0x28 /* PU:0x00000000 */
  105. #define IDX_IO_REC_DMA_LEN_1 0x2c /* PU:0x0000 */
  106. #define IDX_IO_REC_DMA_LEN_2 0x2e /* PU:0x0000 */
  107. #define IDX_IO_REC_DMA_CURRPOS 0x30 /* PU:0x00000000 */
  108. #define IDX_IO_REC_DMA_CURROFS 0x34 /* PU:0x00000000 */
  109. #define IDX_IO_REC_SOUNDFORMAT 0x36 /* PU:0x0000 */
  110. /** hmm, what is this I/O area for? MPU401?? or external DAC via I2S?? (after playback, recording, ???, timer) **/
  111. #define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init, PU:0x0000 */
  112. /* general */
  113. #define IDX_IO_42H 0x42 /* PU:0x0001 */
  114. /** DirectX timer, main interrupt area (FIXME: and something else?) **/
  115. #define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */
  116. /* timer countdown value; triggers IRQ when timer is finished */
  117. #define TIMER_VALUE_MASK 0x000fffffUL
  118. /* activate timer countdown */
  119. #define TIMER_COUNTDOWN_ENABLE 0x01000000UL
  120. /* trigger timer IRQ on zero transition */
  121. #define TIMER_IRQ_ENABLE 0x02000000UL
  122. /* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?)
  123. * had 0x0020 set upon IRQ handler */
  124. #define TIMER_IRQ_ACK 0x04000000UL
  125. #define IDX_IO_IRQSTATUS 0x64
  126. /* some IRQ bit in here might also be used to signal a power-management timer
  127. * timeout, to request shutdown of the chip (e.g. AD1815JS has such a thing).
  128. * Some OPL3 hardware (e.g. in LM4560) has some special timer hardware which
  129. * can trigger an OPL3 timer IRQ, so maybe there's such a thing as well... */
  130. #define IRQ_PLAYBACK 0x0001
  131. #define IRQ_RECORDING 0x0002
  132. #define IRQ_UNKNOWN1 0x0004 /* most probably I2S port */
  133. #define IRQ_GAMEPORT 0x0008 /* Interrupt of Digital(ly) Enhanced Game Port */
  134. #define IRQ_MPU401 0x0010
  135. #define IRQ_TIMER 0x0020 /* DirectX timer */
  136. #define IRQ_UNKNOWN2 0x0040 /* probably unused, or possibly I2S port? */
  137. #define IRQ_UNKNOWN3 0x0080 /* probably unused, or possibly I2S port? */
  138. #define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */
  139. /* this is set to e.g. 0x3ff or 0x300, and writable;
  140. * maybe some buffer limit, but I couldn't find out more, PU:0x00ff: */
  141. #define IDX_IO_SOME_VALUE 0x68
  142. #define IO_68_RANDOM_TOGGLE1 0x0100 /* toggles randomly */
  143. #define IO_68_RANDOM_TOGGLE2 0x0200 /* toggles randomly */
  144. /* umm, nope, behaviour of these bits changes depending on what we wrote
  145. * to 0x6b!!
  146. * And they change upon playback/stop, too:
  147. * Writing a value to 0x68 will display this exact value during playback,
  148. * too but when stopped it can fall back to a rather different
  149. * seemingly random value). Hmm, possibly this is a register which
  150. * has a remote shadow which needs proper device supply which only exists
  151. * in case playback is active? Or is this driver-induced?
  152. */
  153. /* this WORD can be set to have bits 0x0028 activated (FIXME: correct??);
  154. * actually inhibits PCM playback!!! maybe power management??: */
  155. #define IDX_IO_6AH 0x6A /* WRITE_ONLY! */
  156. /* bit 5: enabling this will activate permanent counting of bytes 2/3
  157. * at gameport I/O (0xb402/3) (equal values each) and cause
  158. * gameport legacy I/O at 0x0200 to be _DISABLED_!
  159. * Is this Digital Enhanced Game Port Enable??? Or maybe it's Testmode
  160. * for Enhanced Digital Gameport (see 4D Wave DX card): */
  161. #define IO_6A_SOMETHING1_GAMEPORT 0x0020
  162. /* bit 8; sure, this _pauses_ playback (later resumes at same spot!),
  163. * but what the heck is this really about??: */
  164. #define IO_6A_PAUSE_PLAYBACK_BIT8 0x0100
  165. /* bit 9; sure, this _pauses_ playback (later resumes at same spot!),
  166. * but what the heck is this really about??: */
  167. #define IO_6A_PAUSE_PLAYBACK_BIT9 0x0200
  168. /* BIT8 and BIT9 are _NOT_ able to affect OPL3 MIDI playback,
  169. * thus it suggests influence on PCM only!!
  170. * However OTOH there seems to be no bit anywhere around here
  171. * which is able to disable OPL3... */
  172. /* bit 10: enabling this actually changes values at legacy gameport
  173. * I/O address (0x200); is this enabling of the Digital Enhanced Game Port???
  174. * Or maybe this simply switches off the NE558 circuit, since enabling this
  175. * still lets us evaluate button states, but not axis states */
  176. #define IO_6A_SOMETHING2_GAMEPORT 0x0400
  177. /* writing 0x0300: causes quite some crackling during
  178. * PC activity such as switching windows (PCI traffic??
  179. * --> FIFO/timing settings???) */
  180. /* writing 0x0100 plus/or 0x0200 inhibits playback */
  181. /* since the Windows .INF file has Flag_Enable_JoyStick and
  182. * Flag_Enable_SB_DOS_Emulation directly together, it stands to reason
  183. * that some other bit in this same register might be responsible
  184. * for SB DOS Emulation activation (note that the file did NOT define
  185. * a switch for OPL3!) */
  186. #define IDX_IO_6CH 0x6C /* unknown; fully read-writable */
  187. #define IDX_IO_6EH 0x6E
  188. /* writing 0xffff returns 0x83fe (or 0x03fe only).
  189. * writing 0x83 (and only 0x83!!) to 0x6f will cause 0x6c to switch
  190. * from 0000 to ffff. */
  191. /* further I/O indices not saved/restored and not readable after writing,
  192. * so probably not used */
  193. /*** Gameport area port indices ***/
  194. /* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */
  195. #define AZF_IO_SIZE_GAME 0x08
  196. #define AZF_IO_SIZE_GAME_PM 0x06
  197. enum {
  198. AZF_GAME_LEGACY_IO_PORT = 0x200
  199. };
  200. #define IDX_GAME_LEGACY_COMPATIBLE 0x00
  201. /* in some operation mode, writing anything to this port
  202. * triggers an interrupt:
  203. * yup, that's in case IDX_GAME_01H has one of the
  204. * axis measurement bits enabled
  205. * (and of course one needs to have GAME_HWCFG_IRQ_ENABLE, too) */
  206. #define IDX_GAME_AXES_CONFIG 0x01
  207. /* NOTE: layout of this register awfully similar (read: "identical??")
  208. * to AD1815JS.pdf (p.29) */
  209. /* enables axis 1 (X axis) measurement: */
  210. #define GAME_AXES_ENABLE_1 0x01
  211. /* enables axis 2 (Y axis) measurement: */
  212. #define GAME_AXES_ENABLE_2 0x02
  213. /* enables axis 3 (X axis) measurement: */
  214. #define GAME_AXES_ENABLE_3 0x04
  215. /* enables axis 4 (Y axis) measurement: */
  216. #define GAME_AXES_ENABLE_4 0x08
  217. /* selects the current axis to read the measured value of
  218. * (at IDX_GAME_AXIS_VALUE):
  219. * 00 = axis 1, 01 = axis 2, 10 = axis 3, 11 = axis 4: */
  220. #define GAME_AXES_READ_MASK 0x30
  221. /* enable to have the latch continuously accept ADC values
  222. * (and continuously cause interrupts in case interrupts are enabled);
  223. * AD1815JS.pdf says it's ~16ms interval there: */
  224. #define GAME_AXES_LATCH_ENABLE 0x40
  225. /* joystick data (measured axes) ready for reading: */
  226. #define GAME_AXES_SAMPLING_READY 0x80
  227. /* NOTE: other card specs (SiS960 and others!) state that the
  228. * game position latches should be frozen when reading and be freed
  229. * (== reset?) after reading!!!
  230. * Freezing most likely means disabling 0x40 (GAME_AXES_LATCH_ENABLE),
  231. * but how to free the value? */
  232. /* An internet search for "gameport latch ADC" should provide some insight
  233. * into how to program such a gameport system. */
  234. /* writing 0xf0 to 01H once reset both counters to 0, in some special mode!?
  235. * yup, in case 6AH 0x20 is not enabled
  236. * (and 0x40 is sufficient, 0xf0 is not needed) */
  237. #define IDX_GAME_AXIS_VALUE 0x02
  238. /* R: value of currently configured axis (word value!);
  239. * W: trigger axis measurement */
  240. #define IDX_GAME_HWCONFIG 0x04
  241. /* note: bits 4 to 7 are never set (== 0) when reading!
  242. * --> reserved bits? */
  243. /* enables IRQ notification upon axes measurement ready: */
  244. #define GAME_HWCFG_IRQ_ENABLE 0x01
  245. /* these bits choose a different frequency for the
  246. * internal ADC counter increment.
  247. * hmm, seems to be a combo of bits:
  248. * 00 --> standard frequency
  249. * 10 --> 1/2
  250. * 01 --> 1/20
  251. * 11 --> 1/200: */
  252. #define GAME_HWCFG_ADC_COUNTER_FREQ_MASK 0x06
  253. /* enable gameport legacy I/O address (0x200)
  254. * I was unable to locate any configurability for a different address: */
  255. #define GAME_HWCFG_LEGACY_ADDRESS_ENABLE 0x08
  256. /*** MPU401 ***/
  257. #define AZF_IO_SIZE_MPU 0x04
  258. #define AZF_IO_SIZE_MPU_PM 0x04
  259. /*** OPL3 synth ***/
  260. #define AZF_IO_SIZE_OPL3 0x08
  261. #define AZF_IO_SIZE_OPL3_PM 0x06
  262. /* hmm, given that a standard OPL3 has 4 registers only,
  263. * there might be some enhanced functionality lurking at the end
  264. * (especially since register 0x04 has a "non-empty" value 0xfe) */
  265. /*** mixer I/O area port indices ***/
  266. /* (only 0x22 of 0x40 bytes saved/restored by Windows driver)
  267. * UNFORTUNATELY azf3328 is NOT truly AC97 compliant: see main file intro */
  268. #define AZF_IO_SIZE_MIXER 0x40
  269. #define AZF_IO_SIZE_MIXER_PM 0x22
  270. #define MIXER_VOLUME_RIGHT_MASK 0x001f
  271. #define MIXER_VOLUME_LEFT_MASK 0x1f00
  272. #define MIXER_MUTE_MASK 0x8000
  273. #define IDX_MIXER_RESET 0x00 /* does NOT seem to have AC97 ID bits */
  274. #define IDX_MIXER_PLAY_MASTER 0x02
  275. #define IDX_MIXER_MODEMOUT 0x04
  276. #define IDX_MIXER_BASSTREBLE 0x06
  277. #define MIXER_BASSTREBLE_TREBLE_VOLUME_MASK 0x000e
  278. #define MIXER_BASSTREBLE_BASS_VOLUME_MASK 0x0e00
  279. #define IDX_MIXER_PCBEEP 0x08
  280. #define IDX_MIXER_MODEMIN 0x0a
  281. #define IDX_MIXER_MIC 0x0c
  282. #define MIXER_MIC_MICGAIN_20DB_ENHANCEMENT_MASK 0x0040
  283. #define IDX_MIXER_LINEIN 0x0e
  284. #define IDX_MIXER_CDAUDIO 0x10
  285. #define IDX_MIXER_VIDEO 0x12
  286. #define IDX_MIXER_AUX 0x14
  287. #define IDX_MIXER_WAVEOUT 0x16
  288. #define IDX_MIXER_FMSYNTH 0x18
  289. #define IDX_MIXER_REC_SELECT 0x1a
  290. #define MIXER_REC_SELECT_MIC 0x00
  291. #define MIXER_REC_SELECT_CD 0x01
  292. #define MIXER_REC_SELECT_VIDEO 0x02
  293. #define MIXER_REC_SELECT_AUX 0x03
  294. #define MIXER_REC_SELECT_LINEIN 0x04
  295. #define MIXER_REC_SELECT_MIXSTEREO 0x05
  296. #define MIXER_REC_SELECT_MIXMONO 0x06
  297. #define MIXER_REC_SELECT_MONOIN 0x07
  298. #define IDX_MIXER_REC_VOLUME 0x1c
  299. #define IDX_MIXER_ADVCTL1 0x1e
  300. /* unlisted bits are unmodifiable */
  301. #define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e
  302. #define MIXER_ADVCTL1_HIFI3D_MASK 0x0300 /* yup, this is missing the high bit that official AC97 contains, plus it doesn't have linear bit value range behaviour but instead acts weirdly (possibly we're dealing with two *different* 3D settings here??) */
  303. #define IDX_MIXER_ADVCTL2 0x20 /* subset of AC97_GENERAL_PURPOSE reg! */
  304. /* unlisted bits are unmodifiable */
  305. #define MIXER_ADVCTL2_LPBK 0x0080 /* Loopback mode -- Win driver: "WaveOut3DBypass"? mutes WaveOut at LineOut */
  306. #define MIXER_ADVCTL2_MS 0x0100 /* Mic Select 0=Mic1, 1=Mic2 -- Win driver: "ModemOutSelect"?? */
  307. #define MIXER_ADVCTL2_MIX 0x0200 /* Mono output select 0=Mix, 1=Mic; Win driver: "MonoSelectSource"?? */
  308. #define MIXER_ADVCTL2_3D 0x2000 /* 3D Enhancement 1=on */
  309. #define MIXER_ADVCTL2_POP 0x8000 /* Pcm Out Path, 0=pre 3D, 1=post 3D */
  310. #define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown??? */
  311. /* driver internal flags */
  312. #define SET_CHAN_LEFT 1
  313. #define SET_CHAN_RIGHT 2
  314. #endif /* __SOUND_AZT3328_H */