datasone / ClevoControl

Control keyboard backlight and fan policy for Clevo Hackintosh
MIT License
32 stars 6 forks source link

The last step, add FC00 and FC01 to OperationRegion, how can i put it into my SSDT #8

Closed xiumuyusky closed 4 years ago

xiumuyusky commented 4 years ago

I followed your steps and made my SSDT like this, now need some help during the last step. Hope for your advice, thx. DefinitionBlock ("", "SSDT", 2, "hack", "_SMCD", 0x00000000) { External (SB.PCI0.LPCB.EC.ECOK, MethodObj) // 0 Arguments External (SB.PCI0.LPCB.EC.FC00, MethodObj) // 0 Arguments External (SB.PCI0.LPCB.EC__.FC01, MethodObj) // 0 Arguments External (SB.WMI_.WMBB, MethodObj) // 3 Arguments

Device (_SB.SMCD)
{
    Name (_HID, EisaId ("PNP0C02") /* PNP Motherboard Resources */)  // _HID: Hardware ID
    Name (_CID, "MON00000")  // _CID: Compatible ID
    Method (WMIB, 3, Serialized)
    {
        ^^WMI.WMBB (Arg0, Arg1, Arg2)
    }

    Name (TACH, Package (0x06)
    {
        "CPU Fan", 
        "FAN0"
    })
    Method (FAN0, 0, Serialized)
    {
        If (\_SB.PCI0.LPCB.EC.ECOK ())
        {
            Local0 = B1B2 (\_SB.PCI0.LPCB.EC.FC01 (), \_SB.PCI0.LPCB.EC.FC00 ())
            If ((Local0 <= Zero))
            {
                Return (Zero)
            }

            Local0 = (0x0020E6BC / Local0)
            Return (Local0)
        }

        Return (Zero)
    }
}

Method (B1B2, 2, NotSerialized)
{
    Return ((Arg0 | (Arg1 << 0x08)))
}

}

datasone commented 4 years ago

As you can see in the code, the FC00 and FC01 variables are external located in SB.PCI0.LPCB.EC, so while the OS parse this SSDT table, it goes through all DSDT and SSDT tables to find such variables. But there are no declarations about those variables in CLEVO's origin tables, that's why we need to add them.

The EmbeddedControl OperationRegion describes all the information retrieved from the Embedded Controller, where the information about fan speed lays. And you should add the corresponding offsets and lengths for values we want.

In short, first find the Field under the OperationRegion with the type EmbeddedControl in DSDT, then add the variable definitions in it, such as for the example in the readme, the EC Field code is (there should be some declarations already)

OperationRegion (EC81, EmbeddedControl, Zero, 0xFF)
Field (EC81, ByteAcc, Lock, Preserve)
{
...
}

and add this

Offset (0xD0),
FC00,   8,
FC01,   8,    // CPU Fan Speed, only CPU fan speed as you only used FAN0 in the SSDT

to make it

OperationRegion (EC81, EmbeddedControl, Zero, 0xFF)
Field (EC81, ByteAcc, Lock, Preserve)
{
...
Offset (0xD0),
FC00,   8,
FC01,   8,
...
}

So now the OS knows there are a byte FC00 variable at offset 0xD0 and a byte FC01 variable at offset 0xD8, which will be used in the FAN0 method.

xiumuyusky commented 4 years ago

As you can see in the code, the FC00 and FC01 variables are external located in SB.PCI0.LPCB.EC, so while the OS parse this SSDT table, it goes through all DSDT and SSDT tables to find such variables. But there are no declarations about those variables in CLEVO's origin tables, that's why we need to add them.

The EmbeddedControl OperationRegion describes all the information retrieved from the Embedded Controller, where the information about fan speed lays. And you should add the corresponding offsets and lengths for values we want.

In short, first find the Field under the OperationRegion with the type EmbeddedControl in DSDT, then add the variable definitions in it, such as for the example in the readme, the EC Field code is (there should be some declarations already)

OperationRegion (EC81, EmbeddedControl, Zero, 0xFF)
Field (EC81, ByteAcc, Lock, Preserve)
{
...
}

and add this

Offset (0xD0),
FC00,   8,
FC01,   8,    // CPU Fan Speed, only CPU fan speed as you only used FAN0 in the SSDT

to make it

OperationRegion (EC81, EmbeddedControl, Zero, 0xFF)
Field (EC81, ByteAcc, Lock, Preserve)
{
...
Offset (0xD0),
FC00,   8,
FC01,   8,
...
}

So now the OS knows there are a byte FC00 variable at offset 0xD0 and a byte FC01 variable at offset 0xD8, which will be used in the FAN0 method.

First, thx for your reply. I know the meaning you said and i have tried it when i use clover and succeed to get the fan monitor. But now i change to opencore and drop the custom DSDT. So i just want to know how to put these OperationRegion and the SSDT-fan together. I tried but failed when i just add it into SSDT and there was a error. I deleted the ()in these values (ex. _SB.PCI0.LPCB.EC.FC01 ()) and no error was there but made no sense (no value showed in IStat).

datasone commented 4 years ago

Well the OperationRegion can not be redefined, so if you'd like to not use custom DSDT, you may refer to Rehabman's patch guide about battery, they both modifies the EC Field so it's completely same.

P.S. In my view, it's not necessary to use complex patches and SSDTs instead of custom DSDT. OpenCore replaces DSDT table as long as you have DSDT aml file provided, so DSDT patches are only more convenient on BIOS settings changes/updates, but as DSDT patches itself relies on the disassemble results, it's always best to re-disassemble when DSDT changes.

xiumuyusky commented 4 years ago

Yean I know, thx for your sharing