#ifndef _IOKIT_K2_H
#define _IOKIT_K2_H
#include <IOKit/IOLocks.h>
#include <IOKit/platform/AppleMacIO.h>
#include "USBKeyLargo.h"
#include "KeyLargoWatchDogTimer.h"
#include "KeyLargo.h"
enum {
kK2DeviceId41 = 0x41, kK2Version0 = 0,
kShastaDeviceId4f = 0x4f,
};
enum {
kK2FCRCount = 11,
kK2FCRBase = 0x00024, kK2FCR10 = 0x00024,
kK2FCR9 = 0x00028,
kK2FCR8 = 0x0002c,
kK2FCR7 = 0x00030,
kK2FCR6 = 0x00034,
kK2FCR0USB0SWReset = 1 << 21, kK2FCR0USB1SWReset = 1 << 25, kK2FCR0RingPMEDisable = 1 << 27,
kK2FCR1PCI1BusReset = 1 << 8, kK2FCR1PCI1SleepResetEn = 1 << 9, kK2FCR1PCI1ClkEnable = 1 << 14, kK2FCR1FWClkEnable = 1 << 15, kK2FCR1FWReset = 1 << 16, kK2FCR1I2S1SWReset = 1 << 18, kK2FCR1GBClkEnable = 1 << 22, kK2FCR1GBPwrDown = 1 << 23, kK2FCR1GBReset = 1 << 24, kK2FCR1SATAClkEnable = 1 << 25, kK2FCR1SATAPwrDown = 1 << 26, kK2FCR1SATAReset = 1 << 27, kK2FCR1UATAClkEnable = 1 << 28, kK2FCR1UATAReset = 1 << 30, kK2FCR1UATAChooseClk66 = 1 << 31, kShastaFCR1I2S2CellEnable = 1 << 4, kShastaFCR1I2S2ClkEnable = 1 << 6, kShastaFCR1I2S2Enable = 1 << 7,
kK2FCR2PWM0AutoStopEn = 1 << 4, kK2FCR2PWM1AutoStopEn = 1 << 5, kK2FCR2PWM2AutoStopEn = 1 << 6, kK2FCR2PWM3AutoStopEn = 1 << 7, kK2FCR2PWM0OverTempEn = 1 << 8, kK2FCR2PWM1OverTempEn = 1 << 9, kK2FCR2PWM2OverTempEn = 1 << 10, kK2FCR2PWM3OverTempEn = 1 << 11, kK2FCR2HTEnableInterrupts = 1 << 15, kK2FCR2SBMPICEnableOutputs = 1 << 16, kK2FCR2SBMPICReset = 1 << 17, kK2FCR2FWLinkOnIntEn = 1 << 18, kK2FCR2FWAltLinkOnSel = 1 << 19, kK2FCR2PWMsEn = 1 << 20, kK2FCR2GBWakeIntEn = 1 << 21, kK2FCR2GBEnergyIntEn = 1 << 22, kK2FCR2BlockExtGPIO1 = 1 << 23, kK2FCR2PCI0BridgeInt = 1 << 24, kK2FCR2PCI1BridgeInt = 1 << 25, kK2FCR2PCI2BridgeInt = 1 << 26, kK2FCR2PCI3BridgeInt = 1 << 27, kK2FCR2PCI4BridgeInt = 1 << 28, kK2FCR2HTNonFatalError = 1 << 30, kK2FCR2HTFatalError = 1 << 31,
kK2FCR3EnableOsc25Shutdown = 1 << 0, kK2FCR3EnableFWPadPwrdown = 1 << 1, kK2FCR3EnableGBpadPwrdown = 1 << 2, kK2FCR3EnablePLL0Shutdown = 1 << 7, kK2FCR3EnablePLL6Shutdown = 1 << 8, kK2FCR3DynClkStopEnable = 1 << 11, kShastaFCR3I2S2Clk18Enable = 1 << 15,
kK2FCR9PCI1Clk66isStopped = 1 << 0,
kK2FCR9PCI2Clk66isStopped = 1 << 1,
kK2FCR9FWClk66isStopped = 1 << 2,
kK2FCR9UATAClk66isStopped = 1 << 3,
kK2FCR9UATAClk100isStopped = 1 << 4,
kK2FCR9PCI3Clk66isStopped = 1 << 5,
kK2FCR9GBClk66isStopped = 1 << 6,
kK2FCR9PCI4Clk66isStopped = 1 << 7,
kK2FCR9SATAClk66isStopped = 1 << 8,
kK2FCR9USB0Clk48isStopped = 1 << 9,
kK2FCR9USB1Clk48isStopped = 1 << 10,
kK2FCR9Clk45isStopped = 1 << 11,
kK2FCR9Clk49isStopped = 1 << 12,
kK2FCR9Osc25Shutdown = 1 << 15,
kK2FCR9ClkStopDelayShift = 29,
kK2FCR9ClkStopDelayMask = 7 << 29
};
enum {
kK2FCR0SleepBitsSet = 0,
kK2FCR0SleepBitsClear = kKeyLargoFCR0USB1CellEnable |
kKeyLargoFCR0USB0CellEnable,
kK2FCR0SCCSleepBitsSet = 0,
kK2FCR0SCCSleepBitsClear = kKeyLargoFCR0SccCellEnable |
kKeyLargoFCR0SccBEnable |
kKeyLargoFCR0SccAEnable,
kK2FCR1SleepBitsSet = 0,
kK2FCR1SleepBitsClear = kKeyLargoFCR1I2S1Enable |
kKeyLargoFCR1I2S1ClkEnable |
kKeyLargoFCR1I2S1CellEnable |
kKeyLargoFCR1I2S0Enable |
kKeyLargoFCR1I2S0ClkEnable |
kKeyLargoFCR1I2S0CellEnable |
kK2FCR1GBClkEnable |
kK2FCR1SATAClkEnable |
kK2FCR1UATAClkEnable,
kK2FCR2SleepBitsSet = 0,
kK2FCR2SleepBitsClear = kK2FCR2SBMPICEnableOutputs,
kK2FCR3SleepBitsSet = 0,
kK2FCR3SleepBitsClear = kK2FCR3EnableOsc25Shutdown,
kK2FCR3RestartBitsSet = 0,
kK2FCR3RestartBitsClear = 0,
kK2FCR4SleepBitsSet = 0,
kK2FCR4SleepBitsClear = 0
};
enum {
kK2GPIOBase = 0x58,
kK2GPIOCount = 51
};
enum {
kHTLinkCapLDTCapOffset = 0x0, kHTLinkCapLinkCtrlOffset = 0x4, kHTLinkCapLDTOffset = 0xC };
class AppleK2Device : public AppleMacIODevice
{
OSDeclareDefaultStructors(AppleK2Device);
public:
bool compareName( OSString * name, OSString ** matched = 0 ) const;
IOReturn getResources( void );
};
class AppleK2 : public KeyLargo
{
OSDeclareDefaultStructors(AppleK2);
private:
UInt32 k2CPUVCoreSelectGPIO;
bool keepSCCenabledInSleep;
void EnableSCC(bool state, UInt8 device, bool type);
void PowerModem(bool state);
void ModemResetLow();
void ModemResetHigh();
void PowerI2S (bool powerOn, UInt32 cellNum);
IOReturn SetPowerSupply (bool powerHi);
void AdjustBusSpeeds ( void );
KeyLargoWatchDogTimer *watchDogTimer;
IOService *fProvider;
UInt32 fPHandle;
const OSSymbol *keyLargo_resetUniNEthernetPhy;
const OSSymbol *keyLargo_restoreRegisterState;
const OSSymbol *keyLargo_syncTimeBase;
const OSSymbol *keyLargo_recalibrateBusSpeeds;
const OSSymbol *keyLargo_saveRegisterState;
const OSSymbol *keyLargo_turnOffIO;
const OSSymbol *keyLargo_writeRegUInt8;
const OSSymbol *keyLargo_safeWriteRegUInt8;
const OSSymbol *keyLargo_safeReadRegUInt8;
const OSSymbol *keyLargo_safeWriteRegUInt32;
const OSSymbol *keyLargo_safeReadRegUInt32;
const OSSymbol *keyLargo_getHostKeyLargo;
const OSSymbol *keyLargo_powerI2S;
const OSSymbol *keyLargo_setPowerSupply;
const OSSymbol *keyLargo_EnableI2SModem;
const OSSymbol *mac_io_publishChildren;
const OSSymbol *mac_io_publishChild;
const OSSymbol *k2_enableFireWireClock;
const OSSymbol *k2_enableEthernetClock;
const OSSymbol *k2_getHTLinkFrequency;
const OSSymbol *k2_setHTLinkFrequency;
const OSSymbol *k2_getHTLinkWidth;
const OSSymbol *k2_setHTLinkWidth;
struct MPICTimers {
UInt32 currentCountRegister;
UInt32 baseCountRegister;
UInt32 vectorPriorityRegister;
UInt32 destinationRegister;
};
typedef struct MPICTimers MPICTimers;
typedef volatile MPICTimers *MPICTimersPtr;
struct K2MPICState {
UInt32 mpicIPI[kKeyLargoMPICIPICount];
UInt32 mpicSpuriousVector;
UInt32 mpicTimerFrequencyReporting;
MPICTimers mpicTimers[kKeyLargoMPICTimerCount];
UInt32 mpicInterruptSourceVectorPriority[kKeyLargoMPICVectorsCount];
UInt32 mpicInterruptSourceDestination[kKeyLargoMPICVectorsCount];
UInt32 mpicCurrentTaskPriorities[kKeyLargoMPICTaskPriorityCount];
};
typedef struct K2MPICState K2MPICState;
typedef volatile K2MPICState *k2MPICStatePtr;
struct K2GPIOState {
UInt32 gpioLevels[2];
UInt8 gpio[kK2GPIOCount];
};
typedef struct K2GPIOState K2GPIOState;
typedef volatile K2GPIOState *k2GPIOStatePtr;
struct K2ConfigRegistersState {
UInt32 mediaBay;
UInt32 featureControl[kK2FCRCount];
};
typedef struct K2ConfigRegistersState K2ConfigRegistersState;
typedef volatile K2ConfigRegistersState *k2ConfigRegistersStatePtr;
struct DBDMAChannelRegisters {
UInt32 commandPtrLo;
UInt32 interruptSelect;
UInt32 branchSelect;
UInt32 waitSelect;
};
typedef struct DBDMAChannelRegisters DBDMAChannelRegisters;
typedef volatile DBDMAChannelRegisters *DBDMAChannelRegistersPtr;
struct K2DBDMAState {
DBDMAChannelRegisters dmaChannel[kKeyLargoDBDMAChannelCount];
};
typedef struct K2DBDMAState K2DBDMAState;
typedef volatile K2DBDMAState *k2DBDMAStatePtr;
struct K2I2SState {
UInt32 i2s[kKeyLargoI2SRegisterCount * kKeyLargoI2SChannelCount];
};
typedef struct K2I2SState K2I2SState;
typedef volatile K2I2SState *k2I2SStateStatePtr;
struct K2State {
bool thisStateIsValid;
K2MPICState savedMPICState;
K2GPIOState savedGPIOState;
K2ConfigRegistersState savedConfigRegistersState;
K2DBDMAState savedDBDMAState;
K2I2SState savedI2SState;
UInt8 savedVIAState[9];
};
typedef struct K2State K2State;
UInt32 htLinkCapabilitiesBase;
K2State savedK2State;
void saveK2State();
void restoreK2State();
IOSimpleLock *mutex;
long long busSpeed;
long clk45RefCount; long clk49RefCount;
OSArray *fPlatformFuncArray;
void resetUniNEthernetPhy(void);
void enablePCIDeviceClock(UInt32 mask, bool enable, IOService *nub);
void EnableI2SModem(bool enable);
bool performFunction(IOPlatformFunction *func, void *pfParam1 = 0,
void *pfParam2 = 0, void *pfParam3 = 0, void *pfParam4 = 0);
void logClockState();
public:
virtual bool init(OSDictionary *);
virtual bool start(IOService *provider);
virtual void stop(IOService *provider);
virtual void publishBelow( IORegistryEntry * root );
virtual void processNub( IOService * nub );
virtual IOService * createNub( IORegistryEntry * from );
virtual IOReturn callPlatformFunction(const OSSymbol *functionName,
bool waitForFunction, void *param1, void *param2,
void *param3, void *param4);
virtual long long syncTimeBase(void);
virtual void recalibrateBusSpeeds(void);
virtual void turnOffK2IO(bool restart);
virtual void setReferenceCounts (void);
virtual void saveRegisterState(void);
virtual void restoreRegisterState(void);
virtual void enableCells();
void safeWriteRegUInt32(unsigned long offset, UInt32 mask, UInt32 data);
void initForPM (IOService *provider);
IOReturn setPowerState(unsigned long powerStateOrdinal, IOService* whatDevice);
virtual bool getHTLinkFrequency (UInt32 *freqResult);
virtual bool setHTLinkFrequency (UInt32 newFreq);
virtual bool getHTLinkWidth (UInt32 *linkOutWidthResult, UInt32 *linkInWidthResult);
virtual bool setHTLinkWidth (UInt32 newLinkOutWidth, UInt32 newLinkInWidth);
};
#endif