Contribute
Register

[Guide] Patching DSDT/SSDT for LAPTOP backlight control

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,134
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
IMPORTANT: 10.12.4 and later

Refer to this guide for backlight implementation: https://www.tonymacx86.com/threads/laptop-backlight-control-using-applebacklightinjector-kext.218222/

Note: This guide can still be used on 10.12.4+ to implement your backlight keys...


Overview


Note: This guide is primarily for Intel HD graphics (HD3000->HD5000+, including now Skylake HD 5x0). Although some of the kexts and patches mentioned here can be used in other scenarios, that is not the focus of this post.

By default, your non-Apple DSDT does not have the necessary trigger to cause AppleBacklight.kext to load. Although it is easy to make it load by adding a PNLF device (aka "Brightness Fix" from my laptop repo), it will likely not work correctly. It may not work at all prior to sleep, and even after sleep the full range of brightness will not be available. This is becuase AppleBacklight.kext only has profiles for panels that appear in actual Apple products and there can be PWM registers that are not initialized by BIOS as OS X expects.

A slightly modified DSDT patch can correct for the problem before sleep, and the issue of full range can be fixed by patching AppleBacklight.kext (or providing an injector kext that does the same thing), or by patching EDID. But still, smooth transitions when using keyboard controls will not work (reason not known).

A complete solution to the problem can be achieved with ACPIBacklight.kext and a more complex DSDT patch.

In addition, a second method using the standard PNLF patch ("Brightness Fix") can be used. That method uses a different kext, IntelBacklight.kext instead of ACPIBacklight.kext. That method will be discussed first, followed by ACPIBacklight.kext. ACPIBacklight.kext is a bit more flexible as it can be used in scenarios where IntelBacklight.kext does not work.

In order to implement brightness you must have working graphics drivers (QE/CI), and you must be using a laptop snb-platorm-id/ig-platform-id. Brightness controls are available only for internal LVDS displays.

Note: IntelBacklight.kext + "Brightness Fix" is the preferred solution. IntelBacklight.kext is faster, has been updated for Skylake integrated graphics. There are no plans to update ACPIBacklight.kext for Skylake graphics.


DSDT patching for IntelBacklight.kext

Using normal methods for patching DSDT: http://www.tonymacx86.com/el-capitan-laptop-support/152573-guide-patching-laptop-dsdt-ssdts.html

The patches are available here: https://github.com/RehabMan/Laptop-DSDT-Patch

Apply: "Brightness Fix".

Note: "Brightness Fix" can be applied to an SSDT if you wish. Unlike the patches specifically for ACPIBacklight.kext, it does not matter. Apply it to only one file though.

Now install IntelBacklight.kext.

It is available here: https://github.com/RehabMan/OS-X-Intel-Backlight

Reboot and test. If it works, you do not have to worry about ACPIBacklight.kext and the more complex patches. For most laptops with integrated Intel graphics hardware, it will work (in fact, it will work in any computer where the conventional ACPIBacklight.kext method discussed below works).

Do continue to read this thread for information on enabling your backlight keys.


DSDT/SSDT patching for ACPIBacklight.kext

There are two different DSDT patches available. One for pre-Haswell (Arrandale, Sandy Bridge/HD3000, Ivy Bridge/HD4000) and one for Haswell, and Broadwell (HD4400/HD4600/HD5000+, HD5500/HD6000+).

You should follow the general guidelines for DSDT patching as presented here: http://www.tonymacx86.com/yosemite-laptop-support/152573-guide-patching-laptop-dsdt-ssdts.html

The patches are available here: https://github.com/RehabMan/Laptop-DSDT-Patch

pre-Haswell: "Brightness Fix (HD3000/HD4000)"
Haswell: "Brightness Fix (Haswell/Broadwell)"

Apply only the brightness patch that applies to your hardware. The patch must be applied to the the file (DSDT or SSDT) where the integrated graphics device is defined. Intel hardware is always at address 0x00020000. Searching for "Name (_ADR, 0x00020000)" is a way to find the device. It is commonly called GFX0, so searching for "Device (GFX0)" is also an effective search most of the time.

The patch will only apply to the file where it finds the device at 0x0002000.

Note: By setting LMAX to Zero, you can cause the patch to use BIOS register values at boot. This can eliminate an extra flash at boot time and may be better for some laptops (the _BCL table is automatically scaled as required).


ACPIBacklight.kext

For complete brightness control including smooth transitions, you need to install ACPIBacklight.kext.

It is available here: https://github.com/RehabMan/OS-X-ACPI-Backlight


IGPU power management

It is common to fix power management for the IGPU at the same time as applying brightness. To implement IGPU PM, apply "Rename GFX0 to IGPU" to DSDT and all patched SSDTs. Failure to apply it universally will likely cause one or more SSDTs to be ignored.

Note: Older versions of the patch required this patch, but newer versions do not have that restriction. IGPU power management is still worthwhile to implement.


Backlight troubleshooting

After installing ACPIBacklight.kext rebooting with the brightness patch in place,you should have an operational brightness slider in SysPrefs->Displays. Keyboard control over backlight is a separate issue.

If your backlight control is not working, it could be due to one or more issues:
- incorrect patch applied
- a previous PNLF patch has been applied to DSDT
- Clover is providing PNLF in DSDT (avoid AddPNLF in ACPI/DSDT/Fixes)
- you forgot to drop OEM SSDTs (Clover: ACPI/SSDT/DropOem=true; Chameleon DropSSDT=Yes)
- renames were not balanced causing OS X to ignore one or more SSDTs
- there are duplicate _DSM methods causing OS X to ignore one or more SSDTs
- your DSDT/SSDTs are out-of-sync with your native DSDT/SSDTs files
- you have not disabled a secondary discrete graphics card in a switched configuration (see guide: http://www.tonymacx86.com/yosemite-laptop-support/163772-guide-disabling-discrete-graphics-dual-gpu-laptops.html)
- your hardware does not use the IGPU PWM backlight controls

To determine if your hardware uses the PWM backlight controls, temporarily remove ACPIBacklight.kext to use AppleBacklight.kext. If the brightness slider in SysPrefs->Displays works (check both before and after display sleep), then your laptop uses the backlight registers and the cause is one of the others mentioned above.

If it does not work, then your laptop doesn't use the backlight registers. In that case, try "Brightness Fix", which will cause ACPIBacklight.kext to use the OEM methods (most of the time, the OEM methods do not work). If your OEM methods actually work (with "Brightness Fix"), you may be able to use "Brightness Fix (ACPI 100)" for smoother transitions and more backlight levels.

It is quite common for ACPIBacklight.kext (and the DSDT patches discussed here) to not work unless you disable the discrete card on switched dual-GPU configurations. Done in BIOS or via DSDT/SSDT patches.


Brightness Keys

The brightness patch will only enable the slider in SysPrefs->Displays. Keyboard control is a separate issue, as the keyboard driver must generate the special codes used to trigger the OS X native backlight controls.

Your brightness keys (usually one of the Fn+F1...F12 keys) may be handled with PS2 or ACPI. Most newer computers use ACPI for these keys. If your trackpad is Synaptics and you're using my fork VoodooPS2Controller.kext (https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller), you can make either case work.

The first step is to determine if they are handled by PS2 or ACPI. With my driver, you can use 'ioio -s ApplePS2Keyboard LogScanCodes 1' to turn on the key logging to system.log. The ioio binary is available here: https://github.com/RehabMan/OS-X-ioio (please read the README for download locations). After turning on key logging, monitor system.log with Console.app to determine what PS2 codes (if any) are generated when you press your keys). If they generate PS2 codes, you can map them to backlight control by following the wiki: https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller/wiki/How-to-Use-Custom-Keyboard-Mapping.

If your keys do not generate PS2 codes, it is likely they generate ACPI events. In order to intercept the ACPI events, you will need to determine which method(s) are called when the keys are pressed. Usually, media keys generate EC queries. A simple strategy is to use ACPIDebug.kext to instrument all EC query methods, then press the keys while monitoring system.log. When you press the keys, the name of the method will be output, which will allow you to patch that method.

Note: It is relatively common that the EC will not generate these events unless a certain version of Windows is being emulated by the DSDT. Make sure you patch DSDT as per the linked guide before getting to this. In particular, one of the "OS Check Fix" patches may be necessary before the EC query methods will be called.

Determining EC query methods:

- install ACPIDebug.kext: https://github.com/RehabMan/OS-X-ACPI-Debug
- add the ACPIDebug repo to MaciASL "Sources" per README
- apply ""Add DSDT Debug Methods"
- apply "Instrument EC Queries"
- reboot
- monitor system.log as you press your brightness keys

After you have determined which methods correspond to the brightness keys, you can patch the methods...

Assuming _Q10 is brightness down, and _Q11 is up.
Code:
into method label _Q10 replace_content
begin
// Brightness Down\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0405)\n
end;
into method label _Q11 replace_content
begin
// Brightness Up\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0406)\n
end;
The 0x0405 corresponds to PS2 keydown/keyup are automatic (e005/e085) for the brightness down key used by Dell laptops. In the default keyboard profile, these correspond to ADB codes 91/90 (brigthness down/up). If your laptop uses a keyboard profile other than the default, you may need to use different codes.

For 10.12+, you might want to generate F14/F15 due to problems with the "real" brightness key codes:
Code:
into method label _Q10 replace_content
begin
// Brightness Down\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0365) //F14\n
end;
into method label _Q11 replace_content
begin
// Brightness Up\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0366) //F15\n
end;
Note: For 10.12, VoodooPS2Controller.kext (version 1.8.25 or later) has been updated to generate F14/F15 instead of the brightness ADB codes. Make sure you have the latest version installed.

It is possible for both keys (up/down) to generate a call to the same EC query method. This is the case with the Haswell HP Envy, for example. By examining the code it is possible to determine how to disambiguate. As it turns out a variable in the EC is set to indicate the function to be performed when the _Q13 method is invoked. The patch for this case is as follows:

Code:
into method label _Q13 replace_content
begin
Store(HKNO, Local0)\n
If (LEqual(Local0,7))\n
{\n
// Brightness Down\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0405)\n
}\n
If (LEqual(Local0,8))\n
{\n
// Brightness Up\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x0406)\n
}\n
If (LEqual(Local0,4))\n
{\n
// Mirror toggle\n
    Notify(\_SB.PCI0.LPCB.PS2K, 0x046e)\n
}\n
end;
Note: This patch also includes support for the "mirror toggle" function, where the standard PS2 code is 0e6e/0eee (make/break).

Of course, this code is based on the original code in the DSDT for the HP Haswell Envy. It is likely the details for disambiguation in your DSDT differs. You need to read the original code and make the adjustments to the replacement code as necessary.

As another example, some of the recent Dell laptops have a complex path from EC queries (or even a single query method) through NEVT that eventually lands in the BRT6 method. Resulting in the following patch:
Code:
into method label BRT6 replace_content
begin
    If (LEqual (Arg0, One))\n
    {\n
// Brightness Up\n
        Notify (^^LPCB.PS2K, 0x0406)\n
    }\n
    If (And (Arg0, 0x02))\n
    {\n
// Brightness Down\n
        Notify (^^LPCB.PS2K, 0x0405)\n
    }\n
end;
Recent laptops are showing even more complex scenarios. Some use GPE methods instead of EC queries (meaning you must instrument GPE methods to determine which one). And some funnel all events through one GPE method typically routing through a single method (typically NEVT). See here for a detailed walkthrough/example: http://www.tonymacx86.com/yosemite-laptop-support/152659-guide-patching-dsdt-ssdt-laptop-backlight-control-44.html#post1100377

Note: Not all DSDTs use PS2K as the name for the keyboard object. Search for PNP0303 or PNP030B. Also, not all DSDTs use LPCB as the LPC device. Use the actual path your DSDT uses.

Note on certain Dell laptops

Some Dell laptops generate PS2 codes for the brightness keys. There is built-in support for these PS2 codes in my VoodooPS2Controller.kext. But often these keyboards generate 'make' codes without 'break' codes. That is, they generate codes for the keys going down, but no code for the key being released. This causes the key to infinitely repeat.

The VoodooPS2Keyboard.kext driver has a mechanism to fix this called "Breakless PS2". And there is a built-in Dell profile that has the correct "Breakless PS2" setttings. But you have to select the profile with an SSDT.

The SSDT is checked into the VoodooPS2 project as SSDT-DELL-WN09.dsl: https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller

To use it, save as AML, and place in ACPI/patched so it can be loaded by Clover. If you're using SortedOrder, make sure it refers to the file you place in ACPI/patched.


Note on ELAN (and other) drivers

If you are using another keyboard driver, instead of sending notifications to the PS2 object, you can send them to an object attached to ACPIKeyboard.kext The process is very similar to the process as written above (for ACPI), and is covered well at the ACPIKeyboard github README. See here: https://github.com/RehabMan/OS-X-ACPI-Keyboard

Some newer versions of the ELAN driver may have direct support with codes 0x10 and 0x20. So, no need for ACPIKeyboard.kext in this case.

See below for an example:
Code:
into method label _Q28 replace_content
begin
// Brightness Down\n
    Notify (PS2K, 0x20)\n
end;
into method label _Q30 replace_content
begin
// Brightness Up\n
    Notify (PS2K, 0x10)\n
end;

Providing Feedback

Do not treat this thread as your private troubleshooting thread. If you have a specific problem with your specific laptop, open a separate thread. If you see something here that is in error, or wish to make a contribution, please reply to this thread.


Problem Reporting

Download patchmatic: https://bitbucket.org/RehabMan/os-x-maciasl-patchmatic/downloads/RehabMan-patchmatic-2015-0107.zip
Extract the 'patchmatic' binary from the ZIP. Copy it to /usr/bin, such that you have the binary at /usr/bin/patchmatic.

In terminal,
Code:
if [ -d ~/Downloads/RehabMan ]; then rm -R ~/Downloads/RehabMan; fi
mkdir ~/Downloads/RehabMan
cd ~/Downloads/RehabMan
patchmatic -extract
Note: It is easier if you use copy/paste instead of typing the commands manually.

Post contents of Downloads/RehabMan directory (as ZIP).

Also, post ioreg: http://www.tonymacx86.com/audio/58368-guide-how-make-copy-ioreg.html. Please, use the IORegistryExplorer v2.1 attached to the post! DO NOT reply with an ioreg from any other version of IORegistryExplorer.app.

And output from:
Code:
kextstat|grep -y acpiplat
kextstat|grep -y appleintelcpu
kextstat|grep -y applelpc
Also, post EFI/Clover folder (press F4 at main Clover screen before collecting). Please eliminate 'themes' directory, especially if you have an overabundance of themes installed.

Also post output of:
Code:
sudo touch /System/Library/Extensions && sudo kextcache -u /
 
Last edited:
Joined
Nov 13, 2013
Messages
62
Motherboard
OS X 10.9.5
CPU
intel core 2 duo T6570
Graphics
Nvidia Geforce G 105m
Mac
Classic Mac
Mobile Phone
Dear Mr. Rehabman

Happy New Year!!!

Your topics are so wonderful that I really want to let more people to know them.

It’s good to directly read your original threads, however, you know there are still lots of Chinese people that are not good at English.
So, can I ask for the permission to translate the following threads and post on the PCBETA(a Chinese forum)?

[GUIDE] Native Power Management for Laptops

[GUIDE] Patching LAPTOP DSDT/SSDTs

[GUIDE] Patching DSDT/SSDT for LAPTOP backlight

(Of course, I'll provide the original link in my each translated version.)

Thanks in advance and look forward to your reply.
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,134
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Dear Mr. Rehabman

Happy New Year!!!

Your topics are so wonderful that I really want to let more people to know them.

It’s good to directly read your original threads, however, you know there are still lots of Chinese people that are not good at English.
So, can I ask for the permission to translate the following threads and post on the PCBETA(a Chinese forum)?

[GUIDE] Native Power Management for Laptops

[GUIDE] Patching LAPTOP DSDT/SSDTs

[GUIDE] Patching DSDT/SSDT for LAPTOP backlight

(Of course, I'll provide the original link in my each translated version.)

Thanks in advance and look forward to your reply.
I appreciate you asking, and of course the answer is yes...
 
Joined
Nov 7, 2014
Messages
189
Motherboard
ASUS Z370-A
CPU
i7-8700K
Graphics
Radeon VII
Mac
iMac
I appreciate you asking, and of course the answer is yes...
Happy new year ! MR Rehabman!

I am so happy that there will be so many Chinese will benefit from you .

Great Rehabman !:thumbup:
 
Joined
May 9, 2011
Messages
5,936
Motherboard
GA-Z170X-Gaming 3
CPU
i7-6700
Graphics
Gigabyte GTX 970 WINDFORCE / Intel HD Graphics 530
Mac
iMac
Mobile Phone
iOS
Hi RehabMan,
Kindly share the exact link for downloading the ioio binary. I am failing to find it from the read me file.

Thanks in advance,
Jithin Chandran
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,134
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Hi RehabMan,
Kindly share the exact link for downloading the ioio binary. I am failing to find it from the read me file.

Thanks in advance,
Jithin Chandran
It is linked by the section marked "Downloads:"...
 
Joined
May 9, 2011
Messages
5,936
Motherboard
GA-Z170X-Gaming 3
CPU
i7-6700
Graphics
Gigabyte GTX 970 WINDFORCE / Intel HD Graphics 530
Mac
iMac
Mobile Phone
iOS
It is linked by the section marked "Downloads:"...
Hi RehabMan,
I had checked the section Downloads and there no link available to download the ioio binary. I had downloaded all the .zip files which are available in the https://bitbucket.org/RehabMan/os-x-voodoo-ps2-controller/downloads and searched for the "ioio" after extraction of each zip file. I couldn't find it in anywhere. See the attached screenshots and help me to download the ioio binary.


Thanks in advance,
Jithin Chandran
 

Attachments

Last edited:

RehabMan

Moderator
Joined
May 3, 2012
Messages
191,134
Motherboard
Intel DH67BL
CPU
Core i7-2600K
Graphics
Intel HD 3000
Mac
MacBook Air
Mobile Phone
iOS
Joined
May 9, 2011
Messages
5,936
Motherboard
GA-Z170X-Gaming 3
CPU
i7-6700
Graphics
Gigabyte GTX 970 WINDFORCE / Intel HD Graphics 530
Mac
iMac
Mobile Phone
iOS
Joined
May 9, 2011
Messages
5,936
Motherboard
GA-Z170X-Gaming 3
CPU
i7-6700
Graphics
Gigabyte GTX 970 WINDFORCE / Intel HD Graphics 530
Mac
iMac
Mobile Phone
iOS
Hi RehabMan,
I had enabled the key logging with the command "ioio -s ApplePS2Keyboard LogScanCodes 1" and checked the key press values in console.app. When i am pressing the keys "FN+Left Arrow" & "FN+Right Arrow" it generating the codes "e02e=49" & "e030=48" (screenshot attached). Actually these keys are for "Volume Down" & "Volume UP". When i am pressing the brightness control keys (i.e., "FN+UP ARROW" & "FN+DOWN ARROW") no PS2 codes are generating. Is they are generating ACPI events instead of PS2 codes? Can i go ahead with Determining EC query methods??

Thanks In Advance,
Jithin Chandran
 

Attachments

Top