From 9ff4dab7512018b2c57c690d4c42d03dbfeba9ef Mon Sep 17 00:00:00 2001 From: Feng Yang <76449491+preflight-f@users.noreply.github.com> Date: Sat, 15 Jan 2022 21:31:14 +0800 Subject: [PATCH] Fixed maximum backlight level on Ice Lake IGPUs (#97) --- WhateverGreen/kern_igfx_backlight.cpp | 8 ++++++++ WhateverGreen/kern_igfx_backlight.hpp | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/WhateverGreen/kern_igfx_backlight.cpp b/WhateverGreen/kern_igfx_backlight.cpp index 9e3d695e..2f96f1d8 100644 --- a/WhateverGreen/kern_igfx_backlight.cpp +++ b/WhateverGreen/kern_igfx_backlight.cpp @@ -184,6 +184,14 @@ void IGFX::BacklightRegistersFix::wrapCFLWriteRegisterPWMDuty1(void *controller, DBGLOG("igfx", "BLR: [CFL+] WriteRegister32: Called with register 0x%x and value 0x%x.", reg, value); PANIC_COND(reg != BXT_BLC_PWM_DUTY1, "igfx", "Fatal Error: Register should be BXT_BLC_PWM_DUTY1."); + if (value && callbackIGFX->modBacklightRegistersFix.driverBacklightFrequency == 0) { + // CFL+ backlight additional fix. + DBGLOG("igfx", "BLR: [CFL+] WriteRegister32: Backlight additional fix was entered."); + uint32_t registerValue = callbackIGFX->readRegister32(controller, SFUSE_STRAP); + uint32_t selectedFreq = (registerValue & SFUSE_STRAP_RAW_FREQUENCY) ? ICL_FREQ_RAW : ICL_FREQ_NORMAL; + wrapCFLWriteRegisterPWMFreq1(controller, BXT_BLC_PWM_FREQ1, selectedFreq); + } + if (callbackIGFX->modBacklightRegistersFix.driverBacklightFrequency && callbackIGFX->modBacklightRegistersFix.targetBacklightFrequency) { // Translate the PWM duty cycle between the driver scale value and the HW scale value uint32_t rescaledValue = static_cast((value * static_cast(callbackIGFX->modBacklightRegistersFix.targetBacklightFrequency)) / static_cast(callbackIGFX->modBacklightRegistersFix.driverBacklightFrequency)); diff --git a/WhateverGreen/kern_igfx_backlight.hpp b/WhateverGreen/kern_igfx_backlight.hpp index 6d5aa77d..5ba8ae92 100644 --- a/WhateverGreen/kern_igfx_backlight.hpp +++ b/WhateverGreen/kern_igfx_backlight.hpp @@ -20,6 +20,16 @@ static constexpr uint32_t BXT_BLC_PWM_CTL1 = 0xC8250; static constexpr uint32_t BXT_BLC_PWM_FREQ1 = 0xC8254; static constexpr uint32_t BXT_BLC_PWM_DUTY1 = 0xC8258; +static constexpr uint32_t SFUSE_STRAP = 0xC2014; +static constexpr uint32_t SFUSE_STRAP_RAW_FREQUENCY = 1 << 8; + +/** + * Ice Lake freq + * Copied from `AppleIntelFramebufferController::start()` function + */ +static constexpr uint32_t ICL_FREQ_NORMAL = 17777; +static constexpr uint32_t ICL_FREQ_RAW = 22222; + /** * Represents a single brightness adjustment request */