Contribute
Register

[Guide] Laptop backlight control using AppleBacklightFixup.kext

Joined
Jan 8, 2018
Messages
14
Motherboard
0C6XG5
CPU
i5-7200u
Graphics
Intel HD 620 + AMD R7 445
Mobile Phone
  1. Android
hello all,

I tried to follow this guide.
I can see the brightness slider in syspref->displays and I am able to control the brightness from there.
my laptop's native hotkeys for brightness can also adjust the brightness.

but the keys and the slider seem to be out of sync.
(ie. when I change my brightness using hotkeys, the slider doesn't change but the brightness does)

Can anybody help me here?
 

Attachments

  • debug_5800.zip
    1.9 MB · Views: 45

RehabMan

Moderator
Joined
May 3, 2012
Messages
186,497
Motherboard
Intel DH67BL
CPU
i7-2600K
Graphics
HD 3000
Mac
  1. MacBook Air
Mobile Phone
  1. iOS
hello all,

I tried to follow this guide.
I can see the brightness slider in syspref->displays and I am able to control the brightness from there.
my laptop's native hotkeys for brightness can also adjust the brightness.

but the keys and the slider seem to be out of sync.
(ie. when I change my brightness using hotkeys, the slider doesn't change but the brightness does)

Can anybody help me here?

Brightness key mapping is covered in the link provided in post #1 (BRT6 in DSDT is not patched).
Note: Your ACPI configuration is wrong (no need for all those SSDTs in ACPI/patched, see ACPI patching guide linked from the FAQ)
 
Joined
Jan 8, 2018
Messages
14
Motherboard
0C6XG5
CPU
i5-7200u
Graphics
Intel HD 620 + AMD R7 445
Mobile Phone
  1. Android
Brightness key mapping is covered in the link provided in post #1 (BRT6 in DSDT is not patched).

Oh my bad I didn't see it. Thanks.

Note: Your ACPI configuration is wrong (no need for all those SSDTs in ACPI/patched, see ACPI patching guide linked from the FAQ)

Ok alright. I'll remove the ones that are not patched. (But they don't interfere because the AutoMerge is set to True in config.plist, right ?)
 
Joined
Sep 7, 2013
Messages
39
Motherboard
Asus X541U
CPU
I7 7500U
Graphics
HD 620 + 920M
Mac
  1. MacBook
Mobile Phone
  1. Android
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 three components that all work together to create the solution:

- a single pre-built AppleBacklightInjector.kext
- a patch for AppleBacklight in config.plist/KernelAndKextPatches/KextsToPatch
- 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.

Preparation

For brevity, we are going to use Terminal to acquire the files...

To start, make sure you have the Xcode command line tools. At a fresh install, you can just attempt to use 'git' in Terminal:

Code:
git

The system will prompt you to download and install the tools.

After you have downloaded and installed the developer tools, we can use them to acquire the various github content we need for this guide.

Make the Projects directory if you haven't already:
Code:
mkdir ~/Projects
cd ~/Projects

Clone the probook repo (if you haven't already)
Code:
cd ~/Projects
git clone https://github.com/RehabMan/HP-ProBook-4x30s-DSDT-Patch probook.git

Clone the guide/plist repo (if you haven't already)
Code:
cd ~/Projects
git clone https://github.com/RehabMan/OS-X-Clover-Laptop-Config.git guide.git

If you haven't already, make sure you have iasl installed as per ACPI patching guide: https://www.tonymacx86.com/threads/guide-patching-laptop-dsdt-ssdts.152573/

Alternatively, you could download and install iasl with Terminal:
Code:
cd ~/Downloads
curl --remote-name --progress-bar --location https://bitbucket.org/RehabMan/acpica/downloads/iasl.zip
unzip iasl.zip
sudo cp iasl /usr/bin

Now we will build SSDT-PNLF.aml:
Code:
cd ~/Projects/guide.git
make

You will find the resulting SSDT-PNLF.aml at ~/Projects/guide.git/build/SSDT-PNLF.aml.
AppleBacklightInjector.kext is at ~/Projects/probook.git/kexts/AppleBacklightInjector.kext.
And the patch required is in ~/Projects/guide/config_patches.plist.


Installation

To use this technique requires three components:
- SSDT-PNLF.aml in ACPI/patched
- AppleBacklight patch in config.plist/KernelAndKextPatches/KextsToPatch
- AppleBacklightInjector.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.

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 from ~/Projects/guide.git/build/SSDT-PNLF.aml to your EFI/Clover/ACPI/patched. 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.

Add the patch marked with comment "change F%uT%04x to F%uTxxxx in AppleBacklightInjector.kext (credit RehabMan)" from ~/Projects/guide.git/config_patches.plist to your own config.plist at EFI/Clover/config.plist. Use a plist editor such as Xcode or PlistEdit Pro to copy/paste. DO NOT use Clover Configurator.

Install AppleBacklightInjector.kext to /L/E:
Code:
sudo cp -R ~/Projects/probook.git/kexts/AppleBacklightInjector.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.

And since after doing all these tasks it will be the first time you are loading AppleBacklight.kext, and this fix involves a Clover hotpatch, you will likely not have it working on first reboot. So right after booting with all components in place, rebuild cache:

Code:
sudo kextcache -i /

Then reboot.

Clover can only patch kexts in kernel cache, and upon first reboot, it will not be in cache, which is why the rebuild cache and reboot is required.


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.aml at ~/Projects/guide.git/build/SSDT-RMCF.aml.

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.

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.

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.

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/



I have a small problem regarding sleep/wake problem, everytime the laptop go to sleep and wake up, it shows me a grey screen with nothing else, and I need to restart my laptop again. sleep/wake makes the screen goes grey.
will this procedure help me solve this problem??
I have been working as this guide says, and I am beginner in this thing.
please let me know if I am working right as this guide?
and now I don't have brightness bar, how can I have it back again.
all files listed!
 

Attachments

  • myfiles.zip
    19.4 MB · Views: 56

RehabMan

Moderator
Joined
May 3, 2012
Messages
186,497
Motherboard
Intel DH67BL
CPU
i7-2600K
Graphics
HD 3000
Mac
  1. MacBook Air
Mobile Phone
  1. iOS
(But they don't interfere because the AutoMerge is set to True in config.plist, right ?)

I didn't check... waste of time. SSDTs that do not need to be in ACPI/patched should not be placed there.
 

RehabMan

Moderator
Joined
May 3, 2012
Messages
186,497
Motherboard
Intel DH67BL
CPU
i7-2600K
Graphics
HD 3000
Mac
  1. MacBook Air
Mobile Phone
  1. iOS
I have a small problem regarding sleep/wake problem, everytime the laptop go to sleep and wake up, it shows me a grey screen with nothing else, and I need to restart my laptop again. sleep/wake makes the screen goes grey.
will this procedure help me solve this problem??
I have been working as this guide says, and I am beginner in this thing.
please let me know if I am working right as this guide?
and now I don't have brightness bar, how can I have it back again.
all files listed!

Your config.plist is wrong.

Kexts patches (such as the one for AppleBacklight) belong in config.plist/KernelAndKextPatches/KextsToPatch, not config.plist/ACPI/DSDT/Patches.

Read the guide carefully.
 
Joined
Jan 16, 2017
Messages
17
Motherboard
Dell Inspiron 15 7559 / v1.2.2
CPU
Intel i7 6700HQ
Graphics
HD530
Your config.plist is wrong.

Kexts patches (such as the one for AppleBacklight) belong in config.plist/KernelAndKextPatches/KextsToPatch, not config.plist/ACPI/DSDT/Patches.

Read the guide carefully.
After do this update , picture:
upload_2018-3-24_17-28-21.png

the backlight and the sound does not work any more

myfiles
 

Attachments

  • debug_20767.zip
    6.7 MB · Views: 44
Joined
Jun 15, 2013
Messages
6
Motherboard
ASUS K550JX
CPU
Intel Core i5-4200H
Graphics
Intel HD 4600 + GTX 950m
Mac
  1. MacBook Air
Mobile Phone
  1. Android
You are not booting from the EFI/Clover you attached.
Your config.plist (attached) has 22 KextsToPatch.
But your bootlog extracted from ioreg shows only two:
Code:
0:117  0:000  KextsToPatch: 2 requested
0:117  0:000   - [00]: AppleAHCIPort (External icons patch) :: BinPatch :: data len: 8
0:117  0:000   - [01]: AppleUSBXHCIPCI (change 15 port limit to 26 in XHCI kext (100-Series-10.12)) :: BinPatch :: data len: 7
Thanks for letting me know. I had a normal config.plist along with the one with all my patches that I was booting from. After doing a little research, I found out that clover patches kexts only with the main config.plist. After merging those two together into one, all patches were applied and I have my brightness working now! Now all i have to do is fix the brightness keys.

Thank you for the help! I DEFINITELY couldn't have done this without your help! :D
 
Joined
Oct 3, 2015
Messages
170
Motherboard
Dell Inspiron 5520
CPU
i7 3612QM
Graphics
Intel HD4000, 1366x768
Hi!

Is it possible to enable the smooth transition when changing brightness with FN keys?
 
Top