Skip to content

Commit

Permalink
Fixed maximum backlight level on Ice Lake IGPUs (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feng Yang committed Jan 15, 2022
1 parent 5c3ee11 commit 9ff4dab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions WhateverGreen/kern_igfx_backlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ void IGFX::BacklightRegistersFix::wrapCFLWriteRegisterPWMDuty1(void *controller,
DBGLOG("igfx", "BLR: [CFL+] WriteRegister32<BXT_BLC_PWM_DUTY1>: 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<BXT_BLC_PWM_DUTY1>: 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<uint32_t>((value * static_cast<uint64_t>(callbackIGFX->modBacklightRegistersFix.targetBacklightFrequency)) / static_cast<uint64_t>(callbackIGFX->modBacklightRegistersFix.driverBacklightFrequency));
Expand Down
10 changes: 10 additions & 0 deletions WhateverGreen/kern_igfx_backlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 9ff4dab

Please sign in to comment.