KeyLargoPlatform.h [plain text]
#include "PlatformInterface.h"
#include <IOKit/i2c/PPCI2CInterface.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOFilterInterruptEventSource.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IORegistryEntry.h>
#include <IOKit/IOCommandGate.h>
#include <IOKit/ppc/IODBDMA.h>
#include "AppleOnboardAudioUserClient.h"
#define kKL_AUDIO_MAC_IO_BASE_ADDRESS 0x80000000
#define kKL_AUDIO_MAC_IO_SIZE 256
class KeyLargoPlatform : public PlatformInterface {
OSDeclareDefaultStructors(KeyLargoPlatform);
typedef bool GpioActiveState;
typedef UInt8* GpioPtr;
public:
static void testInterruptHandler();
virtual bool init (IOService* device, AppleOnboardAudio* provider, UInt32 inDBDMADeviceIndex);
virtual void setWorkLoop(IOWorkLoop* inWorkLoop) {mWorkLoop = inWorkLoop; return;}
virtual void free();
virtual IOReturn performPlatformSleep ( void );
virtual IOReturn performPlatformWake ( IOService * device );
virtual bool readCodecRegister(UInt8 address, UInt8 subAddress, UInt8 *data, UInt16 len, BusMode mode);
virtual bool writeCodecRegister(UInt8 address, UInt8 subAddress, UInt8 *data, UInt16 len, BusMode mode);
virtual IOReturn setCodecReset ( CODEC_RESET target, GpioAttributes reset );
virtual GpioAttributes getCodecReset ( CODEC_RESET target );
virtual IOReturn requestI2SClockSource(I2SClockFrequency inFrequency);
virtual IOReturn releaseI2SClockSource(I2SClockFrequency inFrequency);
virtual IOReturn setI2SEnable(bool enable);
virtual bool getI2SEnable();
virtual IOReturn setI2SClockEnable(bool enable);
virtual bool getI2SClockEnable();
virtual IOReturn setI2SCellEnable(bool enable);
virtual bool getI2SCellEnable();
virtual IOReturn setSerialFormatRegister(UInt32 serialFormat);
virtual UInt32 getSerialFormatRegister();
virtual IOReturn setDataWordSizes(UInt32 dataWordSizes);
virtual UInt32 getDataWordSizes();
virtual IOReturn setFrameCount(UInt32 value);
virtual UInt32 getFrameCount();
virtual IOReturn setI2SIOMIntControl(UInt32 intCntrl);
virtual UInt32 getI2SIOMIntControl();
virtual IOReturn setPeakLevel ( UInt32 channelTarget, UInt32 levelMeterValue );
virtual UInt32 getPeakLevel ( UInt32 channelTarget );
virtual void initAudioGpioPtr ( const IORegistryEntry * start, const char * gpioName, GpioPtr* gpioH, GpioActiveState* gpioActiveStatePtr, IOService ** intProvider );
virtual IOReturn getGpioPtrAndActiveState ( GPIOSelector theGpio, GpioPtr * gpioPtrPtr, GpioActiveState * activeStatePtr ) ;
virtual GpioAttributes getGpioAttributes ( GPIOSelector theGpio );
virtual IOReturn setGpioAttributes ( GPIOSelector theGpio, GpioAttributes attributes );
virtual IOReturn setClockMux(GpioAttributes muxState);
virtual GpioAttributes getClockMux();
virtual GpioAttributes getCodecErrorInterrupt();
virtual GpioAttributes getCodecInterrupt();
virtual GpioAttributes getComboInJackTypeConnected();
virtual GpioAttributes getComboOutJackTypeConnected();
virtual GpioAttributes getDigitalInConnected();
virtual GpioAttributes getDigitalOutConnected();
virtual GpioAttributes getHeadphoneConnected();
virtual IOReturn setHeadphoneMuteState(GpioAttributes muteState);
virtual GpioAttributes getHeadphoneMuteState();
virtual IOReturn setInputDataMux(GpioAttributes muxState) ;
virtual GpioAttributes getInputDataMux();
virtual GpioAttributes getInternalSpeakerID();
virtual GpioAttributes getLineInConnected();
virtual GpioAttributes getLineOutConnected();
virtual IOReturn setLineOutMuteState(GpioAttributes muteState);
virtual GpioAttributes getLineOutMuteState();
virtual GpioAttributes getSpeakerConnected();
virtual IOReturn setSpeakerMuteState(GpioAttributes muteState);
virtual GpioAttributes getSpeakerMuteState();
UInt8 userClientReadGPIO (UInt32 selector);
void userClientWriteGPIO (UInt32 selector, UInt8 data);
bool getGPIOActiveState (UInt32 gpioSelector);
void setGPIOActiveState (UInt32 selector, UInt8 gpioActiveState);
UInt8 * getGPIOAddress (UInt32 gpioSelector);
bool checkGpioAvailable (UInt32 selector);
virtual void logFCR1();
virtual void logFCR3();
virtual IOReturn registerInterruptHandler (IOService * theDevice, void * interruptHandler, PlatformInterruptSource source );
virtual IOReturn unregisterInterruptHandler (IOService * theDevice, void * interruptHandler, PlatformInterruptSource source );
virtual IODBDMAChannelRegisters * GetInputChannelRegistersVirtualAddress ( IOService * dbdmaProvider );
virtual IODBDMAChannelRegisters * GetOutputChannelRegistersVirtualAddress ( IOService * dbdmaProvider );
virtual void LogDBDMAChannelRegisters ( void );
virtual IOReturn getPlatformState ( PlatformStateStructPtr outState );
virtual IOReturn setPlatformState ( PlatformStateStructPtr inState );
private:
IOWorkLoop* mWorkLoop;
IOService* mKeyLargoService;
IODBDMAChannelRegisters * mIOBaseDMAOutput;
const OSSymbol * mKLI2SPowerSymbolName;
IOReturn gpioWrite( UInt8* gpioAddress, UInt8 data );
GpioPtr mAmplifierMuteGpio;
GpioPtr mAnalogResetGpio;
GpioPtr mClockMuxGpio;
GpioPtr mComboInJackTypeGpio;
GpioPtr mComboOutJackTypeGpio;
GpioPtr mCodecErrorInterruptGpio;
GpioPtr mCodecInterruptGpio;
GpioPtr mDigitalInDetectGpio;
GpioPtr mDigitalOutDetectGpio;
GpioPtr mDigitalResetGpio;
GpioPtr mHeadphoneDetectGpio;
GpioPtr mHeadphoneMuteGpio;
GpioPtr mInputDataMuxGpio;
GpioPtr mInternalSpeakerIDGpio;
GpioPtr mLineInDetectGpio;
GpioPtr mLineOutDetectGpio;
GpioPtr mLineOutMuteGpio;
GpioPtr mSpeakerDetectGpio;
GpioActiveState mAmplifierMuteActiveState;
GpioActiveState mAnalogResetActiveState;
GpioActiveState mClockMuxActiveState;
GpioActiveState mCodecErrorInterruptActiveState;
GpioActiveState mCodecInterruptActiveState;
GpioActiveState mDigitalInDetectActiveState;
GpioActiveState mComboInJackTypeActiveState;
GpioActiveState mDigitalOutDetectActiveState;
GpioActiveState mComboOutJackTypeActiveState;
GpioActiveState mDigitalResetActiveState;
GpioActiveState mHeadphoneDetectActiveState;
GpioActiveState mHeadphoneMuteActiveState;
GpioActiveState mInputDataMuxActiveState;
GpioActiveState mInternalSpeakerIDActiveState;
GpioActiveState mLineInDetectActiveState;
GpioActiveState mLineOutDetectActiveState;
GpioActiveState mLineOutMuteActiveState;
GpioActiveState mSpeakerDetectActiveState;
volatile UInt8 * mHwPtr;
IOService * mCodecIntProvider;
IOService * mCodecErrorIntProvider;
IOService * mDigitalInDetectIntProvider;
IOService * mDigitalOutDetectIntProvider;
IOService * mHeadphoneDetectIntProvider;
IOService * mLineInDetectIntProvider;
IOService * mLineOutDetectIntProvider;
IOService * mSpeakerDetectIntProvider;
IOInterruptEventSource *mHeadphoneDetectIntEventSource;
IOInterruptEventSource *mSpeakerDetectIntEventSource;
IOInterruptEventSource *mLineOutDetectIntEventSource;
IOInterruptEventSource *mLineInDetectIntEventSource;
IOInterruptEventSource *mDigitalOutDetectIntEventSource;
IOInterruptEventSource *mDigitalInDetectIntEventSource;
IOInterruptEventSource *mCodecInterruptEventSource;
IOInterruptEventSource *mCodecErrorInterruptEventSource;
enum extInt_gpio {
intEdgeSEL = 7, positiveEdge = 0, dualEdge = 1 };
enum gpio {
gpioOS = 4, gpioBit0isOutput = 0, gpioMediaBayIsOutput = 1, gpioReservedOutputSel = 2, gpioMPICopenCollector = 3,
gpioAltOE = 3, gpioOE_DDR = 0, gpioOE_Use_OS = 1,
gpioDDR = 2, gpioDDR_INPUT = 0, gpioDDR_OUTPUT = 1,
gpioPIN_RO = 1,
gpioDATA = 0,
gpioBIT_MASK = 1 };
typedef enum i2sReference {
kUseI2SCell0 = 0,
kUseI2SCell1 = 1,
kNoI2SCell = 0xFFFFFFFF
} I2SCell;
I2SCell mI2SInterfaceNumber;
bool findAndAttachI2C();
bool detachFromI2C();
bool openI2C();
void closeI2C();
IOReturn initI2S(IOMemoryMap* map);
UInt32 mI2CPort;
bool mI2C_lastTransactionResult;
PPCI2CInterface* mI2CInterface;
typedef enum SoundFormat
{
kSndIOFormatI2SSony,
kSndIOFormatI2S64x,
kSndIOFormatI2S32x,
kSndIOFormatUnknown
} SoundFormat;
typedef enum TicksPerFrame
{
k64TicksPerFrame = 64, k32TicksPerFrame = 32 } TicksPerFrame;
typedef enum ClockSourceValue
{
kClock49MHz = 49152000, kClock45MHz = 45158400, kClock18MHz = 18432000 } ClockSourceValue;
void * mSoundConfigSpace; void * mIOBaseAddress; void * mIOConfigurationBaseAddress; void * mI2SBaseAddress; IODeviceMemory * mIOBaseAddressMemory; IODeviceMemory * mIOI2SBaseAddressMemory;
static const UInt32 kFCR0Offset;
static const UInt32 kFCR1Offset;
static const UInt32 kFCR2Offset;
static const UInt32 kFCR3Offset;
static const UInt32 kFCR4Offset;
enum FCR1_Bit_Addresses { kI2S1Enable = 20, kI2S1ClkEnBit = 19, kI2S1SwReset = 18, kI2S1CellEn = 17, kI2S0Enable = 13, kI2S0ClkEnBit = 12, kI2S0SwReset = 11, kI2S0CellEn = 10, kChooseI2S0 = 9, kChooseAudio = 7, kAUDIOCellEN = 6, kAudioClkOut_EN_h = 5, kAudioSW_Reset_h = 4, kAudioClkEnBit_h = 3, kAudioClkDiv2_h = 2, kAudio_Sel22MClk = 1,
kAudioClkOut1X_h = 0
};
enum FCR1_Field_Width {
kI2S1Enable_bitWidth = 1, kI2S1ClkEnBit_bitWidth = 1, kI2S1SwReset_bitWidth = 1, kI2S1CellEn_bitWidth = 1, kI2S0Enable_bitWidth = 1, kI2S0ClkEnBit_bitWidth = 1, kI2S0SwReset_bitWidth = 1, kI2S0CellEn_bitWidth = 1, kChooseI2S0_bitWidth = 1, kChooseAudio_bitWidth = 1, kAUDIOCellEN_bitWidth = 1 };
enum FCR3_Bit_Addresses {
kClk18_EN_h = 14, kI2S1_Clk18_EN_h = 13, kClk45_EN_h = 10, kClk49_EN_h = 9, kShutdown_PLLKW4 = 2, kShutdown_PLLKW6 = 1, kShutdown_PLL_Total = 0 };
enum FCR3_FieldWidth {
kClk18_EN_h_bitWidth = 1, kI2S1_Clk18_EN_h_bitWidth = 1, kClk45_EN_h_bitWidth = 1, kClk49_EN_h_bitWidth = 1, kShutdown_PLLKW4_bitWidth = 1, kShutdown_PLLKW6_bitWidth = 1, kShutdown_PLL_Total_bitWidth = 1 };
static const char* kAmpMuteEntry;
static const char* kAnalogHWResetEntry;
static const char* kCodecErrorIrqTypeEntry;
static const char* kCodecIrqTypeEntry;
static const char* kComboInJackTypeEntry;
static const char* kComboOutJackTypeEntry;
static const char* kDigitalHWResetEntry;
static const char* kDigitalInDetectEntry;
static const char* kDigitalOutDetectEntry;
static const char* kHeadphoneDetectInt;
static const char* kHeadphoneMuteEntry;
static const char* kInternalSpeakerIDEntry;
static const char* kLineInDetectInt;
static const char* kLineOutDetectInt;
static const char* kLineOutMuteEntry;
static const char* kSpeakerDetectEntry;
static const char* kNumInputs;
static const char* kDeviceID;
static const char* kSpeakerID;
static const char* kCompatible;
static const char* kI2CAddress;
static const char* kAudioGPIO;
static const char* kAudioGPIOActiveState;
static const char* kIOInterruptControllers;
static const UInt16 kAPPLE_IO_CONFIGURATION_SIZE;
static const UInt16 kI2S_IO_CONFIGURATION_SIZE;
static const UInt32 kI2S0BaseOffset;
static const UInt32 kI2S1BaseOffset;
static const UInt32 kI2SIntCtlOffset;
static const UInt32 kI2SSerialFormatOffset;
static const UInt32 kI2SCodecMsgOutOffset;
static const UInt32 kI2SCodecMsgInOffset;
static const UInt32 kI2SFrameCountOffset;
static const UInt32 kI2SFrameMatchOffset;
static const UInt32 kI2SDataWordSizesOffset;
static const UInt32 kI2SPeakLevelSelOffset;
static const UInt32 kI2SPeakLevelIn0Offset;
static const UInt32 kI2SPeakLevelIn1Offset;
static const UInt32 kI2SClockOffset;
static const UInt32 kI2S0ClockEnable;
static const UInt32 kI2S1ClockEnable;
static const UInt32 kI2S0CellEnable;
static const UInt32 kI2S1CellEnable;
static const UInt32 kI2S0InterfaceEnable;
static const UInt32 kI2S1InterfaceEnable;
virtual IOReturn setHeadphoneDetectInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setSpeakerDetectInterruptHandler (IOService* theDevice, void* interruptHandler);
virtual IOReturn setLineOutDetectInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setLineInDetectInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setDigitalOutDetectInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setDigitalInDetectInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setCodecInterruptHandler(IOService* theDevice, void* interruptHandler);
virtual IOReturn setCodecErrorInterruptHandler(IOService* theDevice, void* interruptHandler);
inline void setKeyLargoRegister(void *klRegister, UInt32 value);
inline UInt32 getKeyLargoRegister(void *klRegister);
inline UInt32 getFCR1();
inline void setFCR1(UInt32 value);
inline UInt32 getFCR3();
inline void setFCR3(UInt32 value);
inline UInt8 assertGPIO(GpioActiveState inState) {return ((0 == inState) ? 0 : 1);}
inline UInt8 negateGPIO(GpioActiveState inState) {return ((0 == inState) ? 1 : 0);}
IORegistryEntry* FindEntryByProperty (const IORegistryEntry * start, const char * key, const char * value);
};