#include "AppleI2S.h"
#include <IOKit/IOLib.h>
#include <IOKit/IODeviceTreeSupport.h>
#define super IOService
OSDefineMetaClassAndStructors(AppleI2S, IOService)
bool AppleI2S::init(OSDictionary *dict)
{
keyLargoDrv = 0;
i2sBaseAddress = 0;
return super::init(dict);
}
void AppleI2S::free(void)
{
super::free();
}
void AppleI2S::stop(IOService *provider)
{
keyLargoDrv = 0;
i2sBaseAddress = 0;
super::stop(provider);
}
IOService *AppleI2S::probe(IOService *provider, SInt32 *score)
{
return(this);
}
bool AppleI2S::start(IOService *nub)
{
OSData *regprop;
IOService *parentDev;
bool temp;
if (!super::start(nub))
return(false);
parentDev = OSDynamicCast(IOService, nub->getParentEntry(gIODTPlane));
if (!parentDev) return(false);
keyLargoDrv = OSDynamicCast(IOService, parentDev->getChildEntry(gIOServicePlane));
if (!keyLargoDrv) return(false);
if ((regprop = OSDynamicCast(OSData, nub->getProperty("reg"))) == 0)
return(false);
else
i2sBaseAddress = *(UInt32 *)regprop->getBytesNoCopy();
temp = nub->callPlatformFunction("mac-io-publishChildren",0,(void*)this,
(void*)0,(void*)0,(void*)0);
publishResource("AppleI2S", this);
return(true);
}
IOReturn AppleI2S::callPlatformFunction( const OSSymbol *functionSymbol,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 )
{
const char *functionName = functionSymbol->getCStringNoCopy();
IOReturn result = kIOReturnUnsupported;
IOService *provider = getProvider();
UInt32 offset;
UInt32 regval;
offset = (UInt32) noMask;
if (strcmp(functionName, kI2SGetIntCtlReg) == 0)
offset = kI2SIntCtlOffset;
else if (strcmp(functionName, kI2SGetSerialFormatReg) == 0)
offset = kI2SSerialFormatOffset;
else if (strcmp(functionName, kI2SGetCodecMsgOutReg) == 0)
offset = kI2SCodecMsgOutOffset;
else if (strcmp(functionName, kI2SGetCodecMsgInReg) == 0)
offset = kI2SCodecMsgInOffset;
else if (strcmp(functionName, kI2SGetFrameCountReg) == 0)
offset = kI2SFrameCountOffset;
else if (strcmp(functionName, kI2SGetFrameMatchReg) == 0)
offset = kI2SFrameMatchOffset;
else if (strcmp(functionName, kI2SGetDataWordSizesReg) == 0)
offset = kI2SDataWordSizesOffset;
else if (strcmp(functionName, kI2SGetPeakLevelSelReg) == 0)
offset = kI2SPeakLevelSelOffset;
else if (strcmp(functionName, kI2SGetPeakLevelIn0Reg) == 0)
offset = kI2SPeakLevelIn0Offset;
else if (strcmp(functionName, kI2SGetPeakLevelIn1Reg) == 0)
offset = kI2SPeakLevelIn1Offset;
if (offset != noMask) {
offset += (UInt32)param1; offset += i2sBaseAddress;
result = keyLargoDrv->callPlatformFunction(kSafeReadRegUInt32,
false, (void *)offset, (void *)®val, 0, 0);
if (result == kIOReturnSuccess)
{
*(UInt32 *)param2 = (UInt32)regval;
return result;
}
}
if (strcmp(functionName, kI2SSetIntCtlReg) == 0)
offset = kI2SIntCtlOffset;
else if (strcmp(functionName, kI2SSetSerialFormatReg) == 0)
offset = kI2SSerialFormatOffset;
else if (strcmp(functionName, kI2SSetCodecMsgOutReg) == 0)
offset = kI2SCodecMsgOutOffset;
else if (strcmp(functionName, kI2SSetCodecMsgInReg) == 0)
offset = kI2SCodecMsgInOffset;
else if (strcmp(functionName, kI2SSetFrameCountReg) == 0)
offset = kI2SFrameCountOffset;
else if (strcmp(functionName, kI2SSetFrameMatchReg) == 0)
offset = kI2SFrameMatchOffset;
else if (strcmp(functionName, kI2SSetDataWordSizesReg) == 0)
offset = kI2SDataWordSizesOffset;
else if (strcmp(functionName, kI2SSetPeakLevelSelReg) == 0)
offset = kI2SPeakLevelSelOffset;
else if (strcmp(functionName, kI2SSetPeakLevelIn0Reg) == 0)
offset = kI2SPeakLevelIn0Offset;
else if (strcmp(functionName, kI2SSetPeakLevelIn1Reg) == 0)
offset = kI2SPeakLevelIn1Offset;
if (offset != noMask) {
offset += (UInt32)param1; offset += i2sBaseAddress; regval = (UInt32)param2;
result = keyLargoDrv->callPlatformFunction(kSafeWriteRegUInt32,
false, (void *)offset, (void *)noMask, (void *)param2, 0);
}
if (offset == noMask) {
if (provider != 0)
result = provider->callPlatformFunction(functionSymbol, waitForFunction,
param1, param2, param3, param4);
}
return result;
}
IOReturn AppleI2S::callPlatformFunction( const char *functionName,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 )
{
return super::callPlatformFunction(functionName, waitForFunction,
param1, param2, param3, param4);
}