#ifndef _AUDIOI2SCONTROL_H
#define _AUDIOI2SCONTROL_H
#include "AudioHardwareCommon.h"
#include "AudioHardwareUtilities.h"
#include "AppleOnboardAudio.h"
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
{
UInt32 i2sSerialFormat;
IOMemoryMap *map ;
} AudioI2SInfo ;
#define kAudioFCR1Mask 0x001E3C00
class AudioI2SControl : public OSObject
{
OSDeclareDefaultStructors(AudioI2SControl);
private:
ClockSource clockSource;
UInt32 mclkDivisor;
UInt32 sclkDivisor;
UInt32 serialFormat;
UInt32 dataFormat;
IODeviceMemory * ioBaseAddressMemory;
IODeviceMemory * ioI2SBaseAddressMemory;
UInt32 ReadWordLittleEndian(void *address,UInt32 offset);
void WriteWordLittleEndian(void *address, UInt32 offset, UInt32 value);
void *soundConfigSpace; void *ioBaseAddress; void *i2sBaseAddress;
UInt8 i2SInterfaceNumber;
public:
bool setSampleParameters(UInt32 sampleRate, UInt32 mclkToFsRatio, ClockSource *pClockSource, UInt32 *pMclkDivisor, UInt32 *pSclkDivisor, UInt32 newSerialFormat);
void setSerialFormatRegister( ClockSource clockSource, UInt32 mclkDivisor, UInt32 sclkDivisor, SoundFormat serialFormat, UInt32 newDataFormat) ;
UInt32 GetIntCtlReg(void);
void SetIntCtlReg(UInt32 value);
UInt32 GetSerialFormatReg(void);
void SetSerialFormatReg(UInt32 value);
UInt32 GetCodecMsgOutReg(void);
void SetCodecMsgOutReg(UInt32 value);
UInt32 GetCodecMsgInReg(void);
void SetCodecMsgInReg(UInt32 value);
UInt32 GetFrameCountReg(void);
void SetFrameCountReg(UInt32 value);
UInt32 GetFrameMatchReg(void);
void SetFrameMatchReg(UInt32 value);
UInt32 GetDataWordSizesReg(void);
void SetDataWordSizesReg(UInt32 value);
UInt32 GetPeakLevelSelReg(void);
void SetPeakLevelSelReg(UInt32 value);
UInt32 GetPeakLevelIn0Reg(void);
void SetPeakLevelIn0Reg(UInt32 value);
UInt32 GetPeakLevelIn1Reg(void);
void SetPeakLevelIn1Reg(UInt32 value);
UInt32 GetCounterReg(void);
UInt32 FCR1GetReg(void);
void Fcr1SetReg(UInt32 value);
UInt32 FCR3GetReg(void);
void Fcr3SetReg(UInt32 value);
void KLSetRegister(UInt32 klRegister, UInt32 value);
UInt32 KLGetRegister(UInt32 klRegister);
static AudioI2SControl *create(AudioI2SInfo *theInfo) ;
protected:
bool init(AudioI2SInfo *theInfo) ;
void free(void) ;
bool clockRun(bool start) ;
UInt32 frameRate(UInt32 index) ;
};
#endif