Contribute
Register

[Guide] Laptop backlight control using AppleBacklightFixup.kext

RehabMan

Moderator
Joined
May 2, 2012
Messages
181,111
Motherboard
Intel DH67BL
CPU
i7-2600K
Graphics
HD 3000
Mac
  1. MacBook Air
Mobile Phone
  1. iOS
Overview

This is going to be a quick guide for how to implement backlight control for laptop internal displays on macOS/OS X.

There is the original backlight guide using ACPIBacklight.kext or IntelBacklight.kext here: https://www.tonymacx86.com/threads/guide-patching-dsdt-ssdt-for-laptop-backlight-control.152659/

Note: The guide above is still useful for mapping your brightness keys. After you have working brightness via SysPrefs->Displays, refer to the original guide for activating the brightness keys.

But as you probably already know, IntelBacklight.kext and ACPIBacklight.kext were broken by the 10.12.4 update.

I wrote about how to use a patched AppleBacklight.kext or AppleBacklightInjector.kext a while ago: https://www.tonymacx86.com/threads/...een-using-patched-applebacklight-kext.121031/

That guide can be a bit complex for the novice. This guide will simplify it by using two components that work together to create the solution:

- a single pre-built AppleBacklightFixup.kext
- SSDT-PNLF.aml to activate the AppleBacklight kext


Requirements

This guide is only for Intel graphics laptops.
It will work with Arrandale, Sandy Bridge, Ivy Bridge, Haswell, Broadwell, Skylake and Kaby Lake. CoffeeLake graphics/brightness control is still a work-in-progress.


Preparation

Download the latest AppleBacklightFixup.kext and SSDT-PNLF.aml from bitbucket: https://bitbucket.org/RehabMan/applebacklightfixup/downloads/

You will find AppleBacklightFixup.kext in the Release folder (of the ZIP) and SSDT-PNLF.aml in the root.

Note: AppleBacklightFixup.kext requires Lilu.kext. You probably already have it from following the laptop guide: https://www.tonymacx86.com/threads/guide-booting-the-os-x-installer-on-laptops-with-clover.148093/


Installation

To use this technique requires three components:
- SSDT-PNLF.aml in ACPI/patched
- AppleBacklightFixup.kext installed to /L/E

Note: If you already have patched your DSDT (or SSDT) with a "Brightness" patch (PNLF), you must remove it! Same if you're using Clover's AddPNLF_1000000 or AddPNLF (in config.plist/ACPI/DSDT/Fixes).

Also Note: The SSDT-PNLF.aml assumes that GFX0 (or VID on Thinkpads) is already renamed to IGPU. It will not work if your IGPU is not at _SB.PCI0.IGPU.

Copy the SSDT-PNLF.aml to your EFI/Clover/ACPI/patched (on your EFI partition). If you're using SortedOrder in your config.plist, make sure you add SSDT-PNLF.aml to it. Also, it must be loaded *after* the OEM SSDTs. For many laptops, the IGPU (formerly GFX0) device is defined in an SSDT, not DSDT, and since SSDT-PNLF is dependent on this device already being defined, the SSDT-PNLF.aml must load after the OEM SSDT that defines it.


After extracting the ZIP install AppleBacklightFixup.kext to /L/E. This example assumes it was downloaded and extracted in your ~/Downloads folder:
Code:
sudo cp -R ~/Downloads/RehabMan-BacklightFixup*/Release/AppleBacklightFixup.kext /Library/Extensions

And I feel like I shouldn't even need to mention this, as it is obvious... but you must remove IntelBacklight.kext (and/or ACPIBacklight.kext) from wherever you installed it.

It is a good idea to check kernel cache after you install any kext:
Code:
sudo kextcache -i /

Then reboot.


Customization

In certain cases, you may wish to modify the PWMMax value used to match the specifics of your framebuffer. This is especially true if you're not using the typical ig-platform-id and your ig-platform-id uses a different PWMMax.

One example would be Haswell ig-platform-id 0xa2e0008, which uses 0x56c instead of the typical 0xad9 (as used by 0xa260006).

In this case you will need to provide a custom LMAX, since the PWMMax determined based on device-id will not match your ig-platform-id.

This can be done by providing an SSDT-RMCF.aml in ACPI/patched. You will find SSDT-RMCF.dsl in the main guide/hotpatch repo: https://github.com/RehabMan/OS-X-Clover-Laptop-Config. Look in the 'hotpatch' folder.

Since modifying ACPI .dsl code is advanced, I'm going to assume you already know how to do it. If you're not familiar with MaciASL, read here:
https://www.tonymacx86.com/threads/guide-patching-laptop-dsdt-ssdts.152573/

For example, the backlight PWMMax is configured by changing:
Code:
        // LMAX: Backlight PWM MAX.  Must match framebuffer in use.
        //
        // Ones: Default will be used (0x710 for Ivy/Sandy, 0xad9 for Haswell/Broadwell)
        // Other values: must match framebuffer
        Name(LMAX, Ones)

To:
Code:
        // LMAX: Backlight PWM MAX.  Must match framebuffer in use.
        //
        // Ones: Default will be used (0x710 for Ivy/Sandy, 0xad9 for Haswell/Broadwell)
        // Other values: must match framebuffer
        Name(LMAX, 0x56c)


Display ID dependencies

Some product/display-IDs as published in EDID present a problem. Although the patches used here will accomplish the correct FxxTxxxx profile selection in AppleBacklight, certain IDs have special case code (somewhere) that cause the backlight to not work.

To fix it, you must inject a patched EDID...

If Clover can automatically detect your EDID, the easy fix is to change your config.plist such that Clover automatically injects a custom EDID with patched product-id. The product-id known to work is 0x9c7c. Just set config.plist/Graphics/EDID/Inject=true, and config.plist/Graphics/EDID/ProductID=0x9c7c.

Note: You cannot patch a custom EDID with the EDID/ProductID setting. That setting is ignored if you're specifying an EDID via config.plist/Graphics/CustomEDID or config.plist/Graphics/EDID/Custom. You must patch the actual EDID data itself.

Note: With the use of WhateverGreen.kext, config.plist/Devices/Properties is used to inject all IGPU properties. Because EDID injection is done by injecting AAPL00,override-no-connect property on the IGPU, and config.plist/Graphics based injection (including config.plist/Graphics/EDID) does not work when using config.plist/Devices/Properties, you must inject EDID by using only config.plist/Devices/Properties. This is "fixed" in my latest build of Clover available from my bitbucket site: Clover_v2.4k_r4701.RM-4961.695d25a4.zip. The same fix should be rolled into a future "official" Clover build from sourceforge at some point. Don't forget to enable the "AAPL00,override-no-connect" property in Devices/Properties/PciRoot(0)/Pci(0x02,0) section (as long as Clover is detecting your EDID, no need to fill the EDID in there, but it has to be present and empty).

Example:
Screen Shot 2018-10-10 at 9.49.38 AM.png

Screen Shot 2018-10-10 at 9.49.27 AM.png


For some laptops (Sony, Fujitsu, to name a couple of common ones), Clover cannot detect your EDID. You will notice it in your Clover bootlog that detected EDID size is zero. For these laptops you are probably already injecting a custom EDID which you extracted (otherwise your internal display would not work). Simply change the product-id in the EDID data to 0x9c7c. Although macOS/OS X does not seem to check it, you should also update the checksum of the EDID to match the new checksum after patching.

Forum user @tosbaha has created a Ruby script that can patch your EDID with the 0x9c7c product id. You can find instructions here: https://www.tonymacx86.com/threads/fixing-brightness-with-custom-edid.219413/


Saving and restoring backlight level across restarts

AppleBacklight.kext stores the current brightness level in NVRAM for restoration across a reboot. It stores it in NVRAM variable 'backlight-level'.

In order for save/restore to work, you must have properly implemented NVRAM. For some laptops native NVRAM does not work, so you need EmuVariableUefi-64.efi. Without EmuVariableUefi-64.efi in drivers64UEFI, native NVRAM is used. With it, emulated NVRAM is used, saved to disk (nvram.plist) at shutdown, and loaded at startup. In order for emulated NVRAM to work, you must have installed "RC scripts" within the Clover installer. Failure to install "RC scripts", but having EmuVariableUefi-64.efi present in drivers64UEFI will cause NVRAM settings to never be saved in nvram.plist.

For some computers, you may be able to get native NVRAM working (without EmuVariableUefi-64.efi) if you use AptioMemoryFix.efi instead of OsxAptioFix*.efi. So AptioMemoryFix.efi is also something to try. Keep in mind AptioMemoryFix.efi is relatively new, so it may not work for everyone.

Also, make sure config.plist/SystemParameters/BacklightLevel is NOT present in your config.plist. You don't want Clover setting the backlight-level to something other than the NVRAM value.

Keep in mind that if you visit Clover Options -> Graphics Injector, that the default for Backlight Level will likely show as 0xFFFF. If you return from there, Clover *will* inject that value, overriding the NVRAM, which is probably not what you expect. To avoid that problem, always blank the setting before exiting from the Options -> Graphics Injector screen.


Ambient Light Sensor

Some laptops have an ambient light sensor device defined in DSDT. This will interfere with backlight restore as they don't tend to be compatible with macOS/OS X ambient light sensor driver (those drivers have Mac SMC dependencies).

Such devices should be disabled by causing _STA to return zero.

You can check your DSDT for an ambient light sensor (could be in an SSDT too) by looking for its _HID identifier: ACPI0008.

For example:
Code:
    Device (ALSD)
    {
        Name (_HID, "ACPI0008")  // _HID: Hardware ID
        Method (_STA, 0, NotSerialized)  // _STA: Status
        {
            If ((ALSE == 0x02))
            {
                Return (0x0B)
            }

            Return (Zero)
        }
...

You can edit the _STA method so it returns zero:
Code:
    Device (ALSD)
    {
        Name (_HID, "ACPI0008")  // _HID: Hardware ID
        Method (_STA, 0, NotSerialized)  // _STA: Status
        {
            Return (0)
        }
...

For some systems, you may need a Fake ALS device (one that never changes) and the appropriate version of FakeSMC.

Read here: https://www.tonymacx86.com/threads/...ghtness-not-saved.222952/page-14#post-1516295

Original info/discovery from @KNNSpeed that lead to the solution here: https://www.tonymacx86.com/threads/...ghtness-not-saved.222952/page-10#post-1515156


Problem Reporting

Read FAQ, "Problem Reporting"
https://www.tonymacx86.com/threads/faq-read-first-laptop-frequent-questions.164990/
 
Last edited:
Thank you so much, i need this.
 
Thanks for the guide @RehabMan! :D

But can you provide further explanation on why the config.plist KextsToPatch patch is needed?
 
When following this guide and upon entering the command "git checkout beta" after cloning the "probook.git" folder in the Projects folder, I am getting this error in terminal: "fatal: Not a git repository (or any of the parent directories): .git"

Then when ignoring this error and after moving forward with cloning the "guide.git" folder and then attempting to build the SSDT-PNLF.aml file, I am getting this error in terminal: "make: iasl: No such file or directory make: *** [build/SSDT-Config.aml] Error 1.

Anyone know why these errors are occurring ?
 
Last edited:
Thanks for the guide @RehabMan! :D

But can you provide further explanation on why the config.plist KextsToPatch patch is needed?

It makes it so the brightness data lookup from ApplePanels only depends on the _UID, not the display-id.
 
When following this guide and upon entering the command "git checkout beta" after cloning the "probook.git" folder in the Projects folder, I am getting this error in terminal: "fatal: Not a git repository (or any of the parent directories): .git"

Then when ignoring this error and after moving forward with cloning the "guide.git" folder and then attempting to build the SSDT-PNLF.aml file, I am getting this error in terminal: "make: iasl: No such file or directory make: *** [build/SSDT-Config.aml] Error 1.

Anyone know why these errors are occurring ?

You must be in the ~/Projects/probook.git folder when you use 'git checkout beta'.
You must also install iasl as per ACPI patching guide: https://www.tonymacx86.com/threads/guide-patching-laptop-dsdt-ssdts.152573/
 
Back
Top