#ifndef __SOUND_AZT3328_H1#define __SOUND_AZT3328_H23/* "PU" == "power-up value", as tested on PCI168 PCI rev. 104* "WRITE_ONLY" == register does not indicate actual bit values */56/*** main I/O area port indices ***/7/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */8#define AZF_IO_SIZE_CTRL 0x809#define AZF_IO_SIZE_CTRL_PM 0x701011/* the driver initialisation suggests a layout of 4 areas12* within the main card control I/O:13* from 0x00 (playback codec), from 0x20 (recording codec)14* and from 0x40 (most certainly I2S out codec).15* And another area from 0x60 to 0x6f (DirectX timer, IRQ management,16* power management etc.???). */1718#define AZF_IO_OFFS_CODEC_PLAYBACK 0x0019#define AZF_IO_OFFS_CODEC_CAPTURE 0x2020#define AZF_IO_OFFS_CODEC_I2S_OUT 0x402122#define IDX_IO_CODEC_DMA_FLAGS 0x00 /* PU:0x0000 */23/* able to reactivate output after output muting due to 8/16bit24* output change, just like 0x0002.25* 0x0001 is the only bit that's able to start the DMA counter */26#define DMA_RESUME 0x0001 /* paused if cleared? */27/* 0x0002 *temporarily* set during DMA stopping. hmm28* both 0x0002 and 0x0004 set in playback setup. */29/* able to reactivate output after output muting due to 8/16bit30* output change, just like 0x0001. */31#define DMA_RUN_SOMETHING1 0x0002 /* \ alternated (toggled) */32/* 0x0004: NOT able to reactivate output */33#define DMA_RUN_SOMETHING2 0x0004 /* / bits */34#define SOMETHING_ALMOST_ALWAYS_SET 0x0008 /* ???; can be modified */35#define DMA_EPILOGUE_SOMETHING 0x001036#define DMA_SOMETHING_ELSE 0x0020 /* ??? */37#define SOMETHING_UNMODIFIABLE 0xffc0 /* unused? not modifiable */38#define IDX_IO_CODEC_IRQTYPE 0x02 /* PU:0x0001 */39/* write back to flags in case flags are set, in order to ACK IRQ in handler40* (bit 1 of port 0x64 indicates interrupt for one of these three types)41* sometimes in this case it just writes 0xffff to globally ACK all IRQs42* settings written are not reflected when reading back, though.43* seems to be IRQ, too (frequently used: port |= 0x07 !), but who knows? */44#define IRQ_SOMETHING 0x0001 /* something & ACK */45#define IRQ_FINISHED_DMABUF_1 0x0002 /* 1st dmabuf finished & ACK */46#define IRQ_FINISHED_DMABUF_2 0x0004 /* 2nd dmabuf finished & ACK */47#define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */48#define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */49#define IRQMASK_UNMODIFIABLE 0xffe0 /* unused? not modifiable */50/* start address of 1st DMA transfer area, PU:0x00000000 */51#define IDX_IO_CODEC_DMA_START_1 0x0452/* start address of 2nd DMA transfer area, PU:0x00000000 */53#define IDX_IO_CODEC_DMA_START_2 0x0854/* both lengths of DMA transfer areas, PU:0x0000000055length1: offset 0x0c, length2: offset 0x0e */56#define IDX_IO_CODEC_DMA_LENGTHS 0x0c57#define IDX_IO_CODEC_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */58/* offset within current DMA transfer area, PU:0x0000 */59#define IDX_IO_CODEC_DMA_CURROFS 0x1460#define IDX_IO_CODEC_SOUNDFORMAT 0x16 /* PU:0x0010 */61/* all unspecified bits can't be modified */62#define SOUNDFORMAT_FREQUENCY_MASK 0x000f63#define SOUNDFORMAT_XTAL1 0x0064#define SOUNDFORMAT_XTAL2 0x0165/* all _SUSPECTED_ values are not used by Windows drivers, so we don't66* have any hard facts, only rough measurements.67* All we know is that the crystal used on the board has 24.576MHz,68* like many soundcards (which results in the frequencies below when69* using certain divider values selected by the values below) */70#define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c | SOUNDFORMAT_XTAL171#define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a | SOUNDFORMAT_XTAL172#define SOUNDFORMAT_FREQ_5510 0x0c | SOUNDFORMAT_XTAL273#define SOUNDFORMAT_FREQ_6620 0x0a | SOUNDFORMAT_XTAL274#define SOUNDFORMAT_FREQ_8000 0x00 | SOUNDFORMAT_XTAL1 /* also 0x0e | SOUNDFORMAT_XTAL1? */75#define SOUNDFORMAT_FREQ_9600 0x08 | SOUNDFORMAT_XTAL176#define SOUNDFORMAT_FREQ_11025 0x00 | SOUNDFORMAT_XTAL2 /* also 0x0e | SOUNDFORMAT_XTAL2? */77#define SOUNDFORMAT_FREQ_SUSPECTED_13240 0x08 | SOUNDFORMAT_XTAL2 /* seems to be 6620 *2 */78#define SOUNDFORMAT_FREQ_16000 0x02 | SOUNDFORMAT_XTAL179#define SOUNDFORMAT_FREQ_22050 0x02 | SOUNDFORMAT_XTAL280#define SOUNDFORMAT_FREQ_32000 0x04 | SOUNDFORMAT_XTAL181#define SOUNDFORMAT_FREQ_44100 0x04 | SOUNDFORMAT_XTAL282#define SOUNDFORMAT_FREQ_48000 0x06 | SOUNDFORMAT_XTAL183#define SOUNDFORMAT_FREQ_SUSPECTED_66200 0x06 | SOUNDFORMAT_XTAL2 /* 66200 (13240 * 5); 64000 may have been nicer :-\ */84#define SOUNDFORMAT_FLAG_16BIT 0x001085#define SOUNDFORMAT_FLAG_2CHANNELS 0x0020868788/* define frequency helpers, for maximum value safety */89enum azf_freq_t {90#define AZF_FREQ(rate) AZF_FREQ_##rate = rate91AZF_FREQ(4000),92AZF_FREQ(4800),93AZF_FREQ(5512),94AZF_FREQ(6620),95AZF_FREQ(8000),96AZF_FREQ(9600),97AZF_FREQ(11025),98AZF_FREQ(13240),99AZF_FREQ(16000),100AZF_FREQ(22050),101AZF_FREQ(32000),102AZF_FREQ(44100),103AZF_FREQ(48000),104AZF_FREQ(66200),105#undef AZF_FREQ106};107108/** DirectX timer, main interrupt area (FIXME: and something else?) **/109#define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */110/* timer countdown value; triggers IRQ when timer is finished */111#define TIMER_VALUE_MASK 0x000fffffUL112/* activate timer countdown */113#define TIMER_COUNTDOWN_ENABLE 0x01000000UL114/* trigger timer IRQ on zero transition */115#define TIMER_IRQ_ENABLE 0x02000000UL116/* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?)117* had 0x0020 set upon IRQ handler */118#define TIMER_IRQ_ACK 0x04000000UL119#define IDX_IO_IRQSTATUS 0x64120/* some IRQ bit in here might also be used to signal a power-management timer121* timeout, to request shutdown of the chip (e.g. AD1815JS has such a thing).122* OPL3 hardware contains several timers which confusingly in most cases123* are NOT routed to an IRQ, but some designs (e.g. LM4560) DO support that,124* so I wouldn't be surprised at all to discover that AZF3328125* supports that thing as well... */126127#define IRQ_PLAYBACK 0x0001128#define IRQ_RECORDING 0x0002129#define IRQ_I2S_OUT 0x0004 /* this IS I2S, right!? (untested) */130#define IRQ_GAMEPORT 0x0008 /* Interrupt of Digital(ly) Enhanced Game Port */131#define IRQ_MPU401 0x0010132#define IRQ_TIMER 0x0020 /* DirectX timer */133#define IRQ_UNKNOWN2 0x0040 /* probably unused, or possibly OPL3 timer? */134#define IRQ_UNKNOWN3 0x0080 /* probably unused, or possibly OPL3 timer? */135#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */136/* this is set to e.g. 0x3ff or 0x300, and writable;137* maybe some buffer limit, but I couldn't find out more, PU:0x00ff: */138#define IDX_IO_SOME_VALUE 0x68139#define IO_68_RANDOM_TOGGLE1 0x0100 /* toggles randomly */140#define IO_68_RANDOM_TOGGLE2 0x0200 /* toggles randomly */141/* umm, nope, behaviour of these bits changes depending on what we wrote142* to 0x6b!!143* And they change upon playback/stop, too:144* Writing a value to 0x68 will display this exact value during playback,145* too but when stopped it can fall back to a rather different146* seemingly random value). Hmm, possibly this is a register which147* has a remote shadow which needs proper device supply which only exists148* in case playback is active? Or is this driver-induced?149*/150151/* this WORD can be set to have bits 0x0028 activated (FIXME: correct??);152* actually inhibits PCM playback!!! maybe power management??: */153#define IDX_IO_6AH 0x6A /* WRITE_ONLY! */154/* bit 5: enabling this will activate permanent counting of bytes 2/3155* at gameport I/O (0xb402/3) (equal values each) and cause156* gameport legacy I/O at 0x0200 to be _DISABLED_!157* Is this Digital Enhanced Game Port Enable??? Or maybe it's Testmode158* for Enhanced Digital Gameport (see 4D Wave DX card): */159#define IO_6A_SOMETHING1_GAMEPORT 0x0020160/* bit 8; sure, this _pauses_ playback (later resumes at same spot!),161* but what the heck is this really about??: */162#define IO_6A_PAUSE_PLAYBACK_BIT8 0x0100163/* bit 9; sure, this _pauses_ playback (later resumes at same spot!),164* but what the heck is this really about??: */165#define IO_6A_PAUSE_PLAYBACK_BIT9 0x0200166/* BIT8 and BIT9 are _NOT_ able to affect OPL3 MIDI playback,167* thus it suggests influence on PCM only!!168* However OTOH there seems to be no bit anywhere around here169* which is able to disable OPL3... */170/* bit 10: enabling this actually changes values at legacy gameport171* I/O address (0x200); is this enabling of the Digital Enhanced Game Port???172* Or maybe this simply switches off the NE558 circuit, since enabling this173* still lets us evaluate button states, but not axis states */174#define IO_6A_SOMETHING2_GAMEPORT 0x0400175/* writing 0x0300: causes quite some crackling during176* PC activity such as switching windows (PCI traffic??177* --> FIFO/timing settings???) */178/* writing 0x0100 plus/or 0x0200 inhibits playback */179/* since the Windows .INF file has Flag_Enable_JoyStick and180* Flag_Enable_SB_DOS_Emulation directly together, it stands to reason181* that some other bit in this same register might be responsible182* for SB DOS Emulation activation (note that the file did NOT define183* a switch for OPL3!) */184#define IDX_IO_6CH 0x6C /* unknown; fully read-writable */185#define IDX_IO_6EH 0x6E186/* writing 0xffff returns 0x83fe (or 0x03fe only).187* writing 0x83 (and only 0x83!!) to 0x6f will cause 0x6c to switch188* from 0000 to ffff. */189190/* further I/O indices not saved/restored and not readable after writing,191* so probably not used */192193194/*** Gameport area port indices ***/195/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */196#define AZF_IO_SIZE_GAME 0x08197#define AZF_IO_SIZE_GAME_PM 0x06198199enum {200AZF_GAME_LEGACY_IO_PORT = 0x200201};202203#define IDX_GAME_LEGACY_COMPATIBLE 0x00204/* in some operation mode, writing anything to this port205* triggers an interrupt:206* yup, that's in case IDX_GAME_01H has one of the207* axis measurement bits enabled208* (and of course one needs to have GAME_HWCFG_IRQ_ENABLE, too) */209210#define IDX_GAME_AXES_CONFIG 0x01211/* NOTE: layout of this register awfully similar (read: "identical??")212* to AD1815JS.pdf (p.29) */213214/* enables axis 1 (X axis) measurement: */215#define GAME_AXES_ENABLE_1 0x01216/* enables axis 2 (Y axis) measurement: */217#define GAME_AXES_ENABLE_2 0x02218/* enables axis 3 (X axis) measurement: */219#define GAME_AXES_ENABLE_3 0x04220/* enables axis 4 (Y axis) measurement: */221#define GAME_AXES_ENABLE_4 0x08222/* selects the current axis to read the measured value of223* (at IDX_GAME_AXIS_VALUE):224* 00 = axis 1, 01 = axis 2, 10 = axis 3, 11 = axis 4: */225#define GAME_AXES_READ_MASK 0x30226/* enable to have the latch continuously accept ADC values227* (and continuously cause interrupts in case interrupts are enabled);228* AD1815JS.pdf says it's ~16ms interval there: */229#define GAME_AXES_LATCH_ENABLE 0x40230/* joystick data (measured axes) ready for reading: */231#define GAME_AXES_SAMPLING_READY 0x80232233/* NOTE: other card specs (SiS960 and others!) state that the234* game position latches should be frozen when reading and be freed235* (== reset?) after reading!!!236* Freezing most likely means disabling 0x40 (GAME_AXES_LATCH_ENABLE),237* but how to free the value? */238/* An internet search for "gameport latch ADC" should provide some insight239* into how to program such a gameport system. */240241/* writing 0xf0 to 01H once reset both counters to 0, in some special mode!?242* yup, in case 6AH 0x20 is not enabled243* (and 0x40 is sufficient, 0xf0 is not needed) */244245#define IDX_GAME_AXIS_VALUE 0x02246/* R: value of currently configured axis (word value!);247* W: trigger axis measurement */248249#define IDX_GAME_HWCONFIG 0x04250/* note: bits 4 to 7 are never set (== 0) when reading!251* --> reserved bits? */252/* enables IRQ notification upon axes measurement ready: */253#define GAME_HWCFG_IRQ_ENABLE 0x01254/* these bits choose a different frequency for the255* internal ADC counter increment.256* hmm, seems to be a combo of bits:257* 00 --> standard frequency258* 10 --> 1/2259* 01 --> 1/20260* 11 --> 1/200: */261#define GAME_HWCFG_ADC_COUNTER_FREQ_MASK 0x06262263/* FIXME: these values might be reversed... */264#define GAME_HWCFG_ADC_COUNTER_FREQ_STD 0265#define GAME_HWCFG_ADC_COUNTER_FREQ_1_2 1266#define GAME_HWCFG_ADC_COUNTER_FREQ_1_20 2267#define GAME_HWCFG_ADC_COUNTER_FREQ_1_200 3268269/* enable gameport legacy I/O address (0x200)270* I was unable to locate any configurability for a different address: */271#define GAME_HWCFG_LEGACY_ADDRESS_ENABLE 0x08272273/*** MPU401 ***/274#define AZF_IO_SIZE_MPU 0x04275#define AZF_IO_SIZE_MPU_PM 0x04276277/*** OPL3 synth ***/278/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */279#define AZF_IO_SIZE_OPL3 0x08280#define AZF_IO_SIZE_OPL3_PM 0x06281/* hmm, given that a standard OPL3 has 4 registers only,282* there might be some enhanced functionality lurking at the end283* (especially since register 0x04 has a "non-empty" value 0xfe) */284285/*** mixer I/O area port indices ***/286/* (only 0x22 of 0x40 bytes saved/restored by Windows driver)287* UNFORTUNATELY azf3328 is NOT truly AC97 compliant: see main file intro */288#define AZF_IO_SIZE_MIXER 0x40289#define AZF_IO_SIZE_MIXER_PM 0x22290291#define MIXER_VOLUME_RIGHT_MASK 0x001f292#define MIXER_VOLUME_LEFT_MASK 0x1f00293#define MIXER_MUTE_MASK 0x8000294#define IDX_MIXER_RESET 0x00 /* does NOT seem to have AC97 ID bits */295#define IDX_MIXER_PLAY_MASTER 0x02296#define IDX_MIXER_MODEMOUT 0x04297#define IDX_MIXER_BASSTREBLE 0x06298#define MIXER_BASSTREBLE_TREBLE_VOLUME_MASK 0x000e299#define MIXER_BASSTREBLE_BASS_VOLUME_MASK 0x0e00300#define IDX_MIXER_PCBEEP 0x08301#define IDX_MIXER_MODEMIN 0x0a302#define IDX_MIXER_MIC 0x0c303#define MIXER_MIC_MICGAIN_20DB_ENHANCEMENT_MASK 0x0040304#define IDX_MIXER_LINEIN 0x0e305#define IDX_MIXER_CDAUDIO 0x10306#define IDX_MIXER_VIDEO 0x12307#define IDX_MIXER_AUX 0x14308#define IDX_MIXER_WAVEOUT 0x16309#define IDX_MIXER_FMSYNTH 0x18310#define IDX_MIXER_REC_SELECT 0x1a311#define MIXER_REC_SELECT_MIC 0x00312#define MIXER_REC_SELECT_CD 0x01313#define MIXER_REC_SELECT_VIDEO 0x02314#define MIXER_REC_SELECT_AUX 0x03315#define MIXER_REC_SELECT_LINEIN 0x04316#define MIXER_REC_SELECT_MIXSTEREO 0x05317#define MIXER_REC_SELECT_MIXMONO 0x06318#define MIXER_REC_SELECT_MONOIN 0x07319#define IDX_MIXER_REC_VOLUME 0x1c320#define IDX_MIXER_ADVCTL1 0x1e321/* unlisted bits are unmodifiable */322#define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e323#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??) */324#define IDX_MIXER_ADVCTL2 0x20 /* subset of AC97_GENERAL_PURPOSE reg! */325/* unlisted bits are unmodifiable */326#define MIXER_ADVCTL2_LPBK 0x0080 /* Loopback mode -- Win driver: "WaveOut3DBypass"? mutes WaveOut at LineOut */327#define MIXER_ADVCTL2_MS 0x0100 /* Mic Select 0=Mic1, 1=Mic2 -- Win driver: "ModemOutSelect"?? */328#define MIXER_ADVCTL2_MIX 0x0200 /* Mono output select 0=Mix, 1=Mic; Win driver: "MonoSelectSource"?? */329#define MIXER_ADVCTL2_3D 0x2000 /* 3D Enhancement 1=on */330#define MIXER_ADVCTL2_POP 0x8000 /* Pcm Out Path, 0=pre 3D, 1=post 3D */331332#define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown??? */333334/* driver internal flags */335#define SET_CHAN_LEFT 1336#define SET_CHAN_RIGHT 2337338/* helper macro to align I/O port ranges to 32bit I/O width */339#define AZF_ALIGN(x) (((x) + 3) & (~3))340341#endif /* __SOUND_AZT3328_H */342343344