hieplpvip / AsusSMC

A VirtualSMC plugin provides native macOS support for ALS, keyboard backlight and Fn keys on Asus laptops
MIT License
170 stars 21 forks source link

Solved: Keyboard Backlight works with patched DSDT but not with Hotpatching #86

Closed mklengel closed 3 years ago

mklengel commented 3 years ago

My Asus G750JM (Haswell, no ALS) works nearly perfect: OpenCore 6.1, Catalina, AsusSMC 1.4.0

The Keyboard Backlight works only with a patched DSDT but not with Hotpatching (no customized DSDT, only SSDT stuff). The keys for this are Fn-F3 (decrease keyboard backlight) and Fn-F4 (increase keyboard backlight). Typing the keys lets pop up a small window so the right methods are called:

Bildschirmfoto 2020-09-13 um 19 54 56

Clearly the outsourcing of the Device ASL0 and the Methods ALSS, ALSC and SKBV from DSDT to SSDT-ALS0 and SSDT-ATKD is the reason for the problem. What I'm doing wrong?

The debug messages during Fn-F3 and Fn-F4 are:

$ log stream --predicate "sender == \"Lilu\"" --style compact | grep atk
2020-09-13 20:08:17.188 Df kernel[0:824] (Lilu) AsusSMC       atk: @ (DBG) Dispatched key 9(0x9), loop 1 time(s)
2020-09-13 20:08:17.188 Df kernel[0:824] (Lilu) AsusSMC       atk: @ (DBG) Received key 197(0xc5)
2020-09-13 20:08:17.896 Df kernel[0:824] (Lilu) AsusSMC       atk: @ (DBG) Dispatched key 8(0x8), loop 1 time(s)
2020-09-13 20:08:17.896 Df kernel[0:824] (Lilu) AsusSMC       atk: @ (DBG) Received key 196(0xc4)

$ log stream --predicate "sender == \"ACPIDebug\"" --style compact
2020-09-13 22:55:52.533 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0C enter"
2020-09-13 22:55:52.533 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0C IANE (0xC5)"
2020-09-13 22:55:52.533 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0C exit"
2020-09-13 22:55:53.124 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0D enter"
2020-09-13 22:55:53.124 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0C IANE (0xC4)"
2020-09-13 22:55:53.124 Df kernel[0:1b4] (ACPIDebug) ACPIDebug: "ACPIDebug: EC _Q0D exit"

Clearly the called methods

ATKD.IANE (0xC5)

and

ATKD.IANE (0xC4)

do not work correctly in my current Non-DSDT case.

\_SB.PCI0.LPCB.EC0.WRAM (0x04B1, Arg0)

I created two files, SSDT-ASL0 and SSDT-ATKD:

// SSDT-ASL0
DefinitionBlock ("", "SSDT", 2, "ACDT", "ALS0", 0x00000000)
{
    External (_SB.ATKD, DeviceObj)

    Device (_SB.ALS0)
    {
        Name (_HID, "ACPI0008" /* Ambient Light Sensor Device */)  // _HID: Hardware ID
        Name (_CID, "smc-als")  // _CID: Compatible ID
        Name (_ALI, 0x012C)  // _ALI: Ambient Light Illuminance
        Name (_ALR, Package ()  // _ALR: Ambient Light Response
        {
            Package ()
            {
                0x64, 
                0x012C
            }
        })
        Method (_STA, 0, NotSerialized)  // _STA: Status
        {
            If (_OSI ("Darwin"))
            {
                Return (0x0F)
            }
            Else
            {
                Return (Zero)
            }
        }
    }

    Scope (_SB.ATKD)
    {
        Method (ALSS, 0, NotSerialized)
        {
            Return (\_SB.ALS0._ALI) /* External reference */
        }

        Method (ALSC, 0, NotSerialized)
        {
            // This method does nothing
        }
    }
}

and

// SSDT-ATKD
DefinitionBlock ("", "SSDT", 2, "ACDT", "ATKD", 0x00000000)
{
    External (_SB.ATKP, IntObj)
    External (_SB.ATKD, DeviceObj)
    External (_SB.ATKD.IANE, MethodObj)    // 1 Arguments
    External (_SB.KBLV, FieldUnitObj)
    External (_SB.ALS0._ALI, IntObj)
    External (_SB.PCI0.LPCB.EC0, DeviceObj)
    External (_SB.PCI0.LPCB.EC0.WRAM, MethodObj)    // 2 Arguments

    External (RMDT, DeviceObj)
    External (RMDT.PUSH, MethodObj)
    External (RMDT.P1, MethodObj)
    External (RMDT.P2, MethodObj)
    External (RMDT.P3, MethodObj)
    External (RMDT.P4, MethodObj)
    External (RMDT.P5, MethodObj)
    External (RMDT.P6, MethodObj)
    External (RMDT.P7, MethodObj)

    Scope (_SB.ATKD)
    {
        Method (SKBV, 1, NotSerialized)
        {
            // \_SB.KBLV = Arg0 / 16
            \_SB.PCI0.LPCB.EC0.WRAM (0x04B1, Arg0)
            Return (Arg0)
        }
    }

    Scope (_SB.PCI0.LPCB.EC0)
    {
        // F1: Sleep (Works)
        Method (_Q0A, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0A enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x5E)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q0A exit")
        }

        // F2: Airplane mode
        Method (_Q0B, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0B enter")
            If (\_SB.ATKP)
            {
                \RMDT.P1 ("ACPIDebug: EC _Q0B IANE (0x7D)")
                \_SB.ATKD.IANE (0x7D)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q0B exit")
        }

        // F3: Decrease keyboard backlight
        Method (_Q0C, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0C enter")
            If (\_SB.ATKP)
            {
                \RMDT.P1 ("ACPIDebug: EC _Q0C IANE (0xC5)")
                \_SB.ATKD.IANE (0xC5)
            }
            else
            {
                \RMDT.P1 ("ACPIDebug: EC _Q0C _SB.ATKP is false")
            }
            \RMDT.P1 ("ACPIDebug: EC _Q0C exit")
        }

        // F4: Increase keyboard backlight
        Method (_Q0D, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0D enter")
            If (\_SB.ATKP)
            {
                \RMDT.P1 ("ACPIDebug: EC _Q0C IANE (0xC4)")
                \_SB.ATKD.IANE (0xC4)
            }
            \RMDT.P1 ("ACPIDebug: EC _Q0D exit")
        }

        // F5: Decrease screen backlight
        Method (_Q0E, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0E enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x20)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q0E exit")
        }

        // F6: Increase screen backlight
        Method (_Q0F, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q0F enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x10)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q0F exit")
        }

        // F7: Turn off screen
        Method (_Q10, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q10 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x35)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q10 exit")
        }

        // F8: Switch monitor
        Method (_Q11, 0, Serialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q11 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x61)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q11 exit")
        }

        // F9: Enable/Disable trackpad
        Method (_Q12, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q12 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x6B)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q12 exit")
        }

        // F10: Mute volume (works, but this method is not reached)
        Method (_Q13, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q13 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x32)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q13 exit")
        }

        // F11: Decrease volume (works, but this method is not reached)
        Method (_Q14, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q14 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x31)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q14 exit")
        }

        // F12: Increase volume (works, but this method is not reached)
        Method (_Q15, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q15 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x30)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q15 exit")
        }

        // Fn Left Arrow
        Method (_Q6C, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q6C enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x40)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q6C exit")
        }

        // Fn Right Arrow
        Method (_Q6D, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q6D enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x41)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q6D exit")
        }

        // Fn Up Arrow
        Method (_Q6E, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q6E enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x43)
            }
            \RMDT.P1 ("ACPIDebug: EC _Q6E exit")
        }

        // Fn Down Arrow
        Method (_Q6F, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q6F enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x45)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q6F exit")
        }

        // Fn Space Key
        Method (_Q71, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q71 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x5C)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q71 exit")
        }

        // Fn C
        Method (_Q72, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q72 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x82)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q72 exit")
        }

        // Fn V
        Method (_Q74, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
        {
            \RMDT.P1 ("ACPIDebug: EC _Q74 enter")
            If (\_SB.ATKP)
            {
                \_SB.ATKD.IANE (0x8A)
            }

            \RMDT.P1 ("ACPIDebug: EC _Q74 exit")
        }
    }
}
hieplpvip commented 3 years ago

Hi, since you have marked this issue as solved, I will close it.

Just a little remark: ALSS and ALSC is not needed on v1.4.0. You can safely remove them.

mklengel commented 3 years ago

Thank you for the information and - of course - your invaluable work.

Regards Michael

„Don’t talk about nothing you know nothing about.“ John Young

Am 15.09.2020 um 19:57 schrieb Hiep Bao Le notifications@github.com:

 Hi, since you have marked this issue as solved, I will close it.

Just a little remark: ALSS and ALSC is not needed on v1.4.0. You can safely remove them.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.