Exemple #1
0
IOReturn LPCSensors::setPowerState(unsigned long powerState, IOService *device)
{
    switch (powerState) {
        // Power Off
        case 0:
            willPowerOff();
            break;

        // Power On
        case 1:
            // Restore fan speed after wake from sleep if it was set before
            for (int index = 0; index < tachometerSensorsLimit(); index ++) {
                if (tachometerControls[index].target >= 0) {
                    tachometerControlInit(index, tachometerControls[index].target);
                }
            }

            hasPoweredOn();

            break;

        default:
            break;
    }
    
	return(IOPMAckImplied);
}
void LPCSensors::hasPoweredOn()
{
    // Restore fan speed after wake from sleep if it was set before
    for (int index = 0; index < tachometerSensorsLimit(); index ++) {
        if (tachometerControls[index].target >= 0) {
            tachometerControlInit(index, tachometerControls[index].target);
        }
    }
    
    // Override, but call super
}
bool SuperIOPlugin::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");
    
    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        char key[7];
        snprintf(key, 7, "FANIN%X", i);
        
        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key)))
            if (!addTachometer(i, (name->getLength() > 0 ? name->getCStringNoCopy() : 0)))
                HWSensorsWarningLog("failed to add tachometer sensor %d", i);
    }
    
    return true;
}
bool LPCSensors::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");

    char key[7];
    UInt16 value = 0;

    // FAN manual control key
    addSensorForKey(KEY_FAN_MANUAL, SMC_TYPE_UI16, SMC_TYPE_UI16_SIZE, kLPCSensorsFanManualSwitch, 0);

    int location = LEFT_LOWER_FRONT;

    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        
        UInt8 fanIndex;

        snprintf(key, 7, "FANIN%X", i);

        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))){
            if (addTachometer(i, name->getLength() > 0 ? name->getCStringNoCopy() : 0, FAN_RPM, 0, (FanLocationType)location++, &fanIndex)){

                if (isTachometerControlable(i) && fanIndex < UINT8_MAX) {

                    tachometerControls[i].number = fanIndex;
                    tachometerControls[i].target = -1;
                    tachometerControls[i].minimum = -1;

                    // Minimum RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_MIN, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanMinController, i);

                    // Maximum RPM
                    snprintf(key, 5, KEY_FORMAT_FAN_MAX, fanIndex);
                    FakeSMCKey::encodeFloatValue(kLPCSensorsMaxRPM, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);
                    setKeyValue(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);

                    // Target RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_TARGET, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanTargetController, i);
                }
            }
            else HWSensorsWarningLog("failed to add tachometer sensor %d", i);
        }
    }

    return true;
}
Exemple #5
0
IOReturn LPCSensors::woorkloopTimerEvent(void)
{
    bool active = false;

    for (int index = 0; index < tachometerSensorsLimit(); index ++) {
        if (tachometerControls[index].active && tachometerControlSample(index)) {
            active = true;
        }
    }

    if (active) {
        timerEventSource->setTimeoutMS(kLPCSensorsControlSamplingInterval);
        timerScheduled = true;
        HWSensorsDebugLog("timer scheduled");
    }
    else {
        timerScheduled = false;
    }
    
    return kIOReturnSuccess;
}
Exemple #6
0
bool LPCSensors::didWriteSensorValue(FakeSMCSensor *sensor, float value)
{
    if (sensor) {
        switch (sensor->getGroup()) {
                
            case kLPCSensorsFanManualSwitch:
                for (int index = 0; index < tachometerSensorsLimit(); index++) {
                    if (isTachometerControlable(index) && !bit_get((UInt16)value, BIT(tachometerControls[index].number))) {
                        tachometerControlCancel(index);
                        tachometerControls[index].target = -1.0;
                    }
                }
                break;

            case kLPCSensorsFanMinController:
                if (isTachometerControlable(sensor->getIndex())) {
                    tachometerControls[sensor->getIndex()].minimum = value;
                    tachometerControlInit(sensor->getIndex(), value > tachometerControls[sensor->getIndex()].target ? value : tachometerControls[sensor->getIndex()].target);
                }
                break;

            case kLPCSensorsFanTargetController:
                if (isTachometerControlable(sensor->getIndex())) {
                    int manual = 0;
                    if (decodeIntValueForKey(KEY_FAN_MANUAL, &manual) && bit_get(manual, BIT(tachometerControls[sensor->getIndex()].number)) > 0 && value > tachometerControls[sensor->getIndex()].minimum) {
                        tachometerControlInit(sensor->getIndex(), value);
                    }
                }
                break;

            default: return false;
                
        }

        return true;
    }

    return false;
}
Exemple #7
0
bool SuperIOMonitor::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");
    
    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        OSString* name = NULL;
        
        char key[7];
            
        snprintf(key, 7, "FANIN%X", i);

        name = OSDynamicCast(OSString, configuration->getObject(key));
        
        UInt64 nameLength = name ? name->getLength() : 0;
        
        if (readTachometer(i) > 10 || nameLength > 0)
            if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0)))
                HWSensorsWarningLog("error adding tachometer sensor %d", i);
    }
    
    return true;
}