#ifndef _AUDIOI2SCONTROL_H
#define _AUDIOI2SCONTROL_H
#include "AudioHardwareCommon.h"
#include "AudioHardwareUtilities.h"
#include "AppleOnboardAudio.h"
#ifdef DEBUGMODE
#define INLINE
#else
#define INLINE inline
#endif
typedef enum SoundFormat
{
kSndIOFormatI2SSony,
kSndIOFormatI2S64x,
kSndIOFormatI2S32x,
kSndIOFormatUnknown
} SoundFormat;
typedef enum TicksPerFrame
{
k64TicksPerFrame = 64, k32TicksPerFrame = 32 } TicksPerFrame;
typedef enum ClockSource
{
kClock49MHz = 49152000, kClock45MHz = 45158400, kClock18MHz = 18432000 } ClockSource;
typedef struct _s_AudioI2SInfo
{
SoundFormat i2sSerialFormat;
IOMemoryMap *map ;
} AudioI2SInfo ;
class AudioI2SControl : public OSObject
{
OSDeclareDefaultStructors(AudioI2SControl);
private:
ClockSource dacaClockSource;
UInt32 dacaMclkDivisor;
UInt32 dacaSclkDivisor;
SoundFormat dacaSerialFormat;
bool setSampleParameters( UInt32 sampleRate, UInt32 mclkToFsRatio) ;
void setSerialFormatRegister( ClockSource clockSource, UInt32 mclkDivisor, UInt32 sclkDivisor, SoundFormat serialFormat) ;
bool dependentSetup(void) ;
UInt32 ReadWordLittleEndian(void *address,UInt32 offset);
void WriteWordLittleEndian(void *address, UInt32 offset, UInt32 value);
void *soundConfigSpace; void *ioBaseAddress; void *ioClockBaseAddress; void *ioStatusRegister_GPIO12;
UInt8 i2SInterfaceNumber;
public:
UInt32 I2S0_GetIntCtlReg();
UInt32 I2S1_GetIntCtlReg();
void I2S0_SetIntCtlReg(UInt32 value);
void I2S1_SetIntCtlReg(UInt32 value);
UInt32 I2S0_GetSerialFormatReg();
UInt32 I2S1_GetSerialFormatReg();
void I2S0_SetSerialFormatReg(UInt32 value);
void I2S1_SetSerialFormatReg(UInt32 value);
UInt32 I2S0_GetCodecMsgOutReg();
UInt32 I2S1_GetCodecMsgOutReg();
void I2S0_SetCodecMsgOutReg(UInt32 value);
void I2S1_SetCodecMsgOutReg(UInt32 value);
UInt32 I2S0_GetCodecMsgInReg();
UInt32 I2S1_GetCodecMsgInReg();
void I2S0_SetCodecMsgInReg(UInt32 value);
void I2S1_SetCodecMsgInReg(UInt32 value);
UInt32 I2S0_GetFrameCountReg();
UInt32 I2S1_GetFrameCountReg();
void I2S0_SetFrameCountReg(UInt32 value);
void I2S1_SetFrameCountReg(UInt32 value);
UInt32 I2S0_GetFrameMatchReg();
UInt32 I2S1_GetFrameMatchReg();
void I2S0_SetFrameMatchReg(UInt32 value);
void I2S1_SetFrameMatchReg(UInt32 value);
UInt32 I2S0_GetDataWordSizesReg();
UInt32 I2S1_GetDataWordSizesReg();
void I2S0_SetDataWordSizesReg(UInt32 value);
void I2S1_SetDataWordSizesReg(UInt32 value);
UInt32 I2S0_GetPeakLevelSelReg();
UInt32 I2S1_GetPeakLevelSelReg();
void I2S0_SetPeakLevelSelReg(UInt32 value);
void I2S1_SetPeakLevelSelReg(UInt32 value);
UInt32 I2S0_GetPeakLevelIn0Reg();
UInt32 I2S1_GetPeakLevelIn0Reg();
void I2S0_SetPeakLevelIn0Reg(UInt32 value);
void I2S1_SetPeakLevelIn0Reg(UInt32 value);
UInt32 I2S0_GetPeakLevelIn1Reg();
UInt32 I2S1_GetPeakLevelIn1Reg();
void I2S0_SetPeakLevelIn1Reg(UInt32 value);
void I2S1_SetPeakLevelIn1Reg(UInt32 value);
UInt32 I2S0_GetCounterReg();
UInt32 I2S1_GetCounterReg();
void KLSetRegister(void *klRegister, UInt32 value);
UInt32 KLGetRegister(void *klRegister);
static AudioI2SControl *create(AudioI2SInfo *theInfo) ;
inline void *getIOStatusRegister_GPIO12(void) { return (ioStatusRegister_GPIO12); } ;
protected:
bool init(AudioI2SInfo *theInfo) ;
void free(void) ;
bool clockRun(bool start) ;
UInt32 frameRate(UInt32 index) ;
} ;
#endif