AppleSMUMonitor.cpp [plain text]
#include "AppleSMUMonitor.h"
#include <IOKit/IODeviceTreeSupport.h>
#include <IOKit/IOLib.h>
OSDefineMetaClassAndStructors(AppleSMUMonitor, IOService);
bool AppleSMUMonitor::start(IOService *provider)
{
OSData *data;
if(!IOService::start(provider))
return false;
data = OSDynamicCast(OSData, provider->getProperty("reg"));
if (!data) {
IOLog("No reg property for AppleSMUDevice\n");
return false;
}
fCommand = *(UInt32 *)data->getBytesNoCopy();
fProvider = provider;
fType = kUnknown;
if ( ( data = OSDynamicCast( OSData, provider->getProperty( "device_type" ) ) ) != NULL )
{
if ( strcmp( "batt-sensors", ( const char * ) data->getBytesNoCopy() ) == 0 )
fType = kBATT_sensor;
}
fSMUGetSensor = OSSymbol::withCString("getSensor");
fSMUGetControl = OSSymbol::withCString("getControl");
fSMUSetControl = OSSymbol::withCString("setControl");
fGetSensorValue = OSSymbol::withCString("getSensorValue");
fGetCurrentValue = OSSymbol::withCString("getCurrentValue");
fGetTargetValue = OSSymbol::withCString("getTargetValue");
fSetTargetValue = OSSymbol::withCString("setTargetValue");
OSIterator *iter;
IOService *child;
iter = provider->getChildIterator(gIODTPlane);
if(!iter)
return false;
while(child = (IOService *)iter->getNextObject()) {
child->attach(this);
child->start(this);
child->registerService();
}
iter->release();
return true;
}
IOReturn AppleSMUMonitor::callPlatformFunction(const OSSymbol *functionName,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4)
{
IOReturn ret;
void *command;
SInt16 val;
SInt32 val32;
if(functionName == fGetSensorValue) {
command = (void *)((UInt32)param1 | fCommand);
if (fType == kBATT_sensor)
{
ret = fProvider->callPlatformFunction(fSMUGetSensor, waitForFunction, command, &val32, (void *)2, NULL);
if (ret == kIOReturnSuccess)
*(SInt32*)param2 = val32;
}
else
{
ret = fProvider->callPlatformFunction(fSMUGetSensor, waitForFunction, command, &val, (void *)2, NULL);
if (ret == kIOReturnSuccess)
*(SInt32*)param2 = val;
}
return ret;
}
else if(functionName == fGetCurrentValue) {
command = (void *)((UInt32)param1 | ((fCommand | kGetCurrent) << kCommandShift));
ret = fProvider->callPlatformFunction(fSMUGetControl, waitForFunction,
command, &val, (void *)2, NULL);
if(ret == kIOReturnSuccess)
*(SInt32*)param2 = val;
return ret;
}
else if(functionName == fGetTargetValue) {
command = (void *)((UInt32)param1 | ((fCommand | kGetTarget) << kCommandShift));
ret = fProvider->callPlatformFunction(fSMUGetControl, waitForFunction,
command, &val, (void *)2, NULL);
if(ret == kIOReturnSuccess)
*(SInt32*)param2 = val;
return(ret);
}
else if(functionName == fSetTargetValue) {
val = (SInt32)param2;
command = (void *)((UInt32)param1 | ((fCommand | kSetTarget) << kCommandShift));
ret = fProvider->callPlatformFunction(fSMUSetControl, waitForFunction,
command, &val, (void *)2, NULL);
return ret;
}
else
return IOService::callPlatformFunction(functionName, waitForFunction,
param1, param2, param3, param4);
}