Skip to content

Commit

Permalink
Save brightness value to VBIOS scratch reg
Browse files Browse the repository at this point in the history
Signed-off-by: Visual Ehrmanntraut <30368284+VisualEhrmanntraut@users.noreply.github.com>
  • Loading branch information
VisualEhrmanntraut committed Apr 1, 2024
1 parent d3d6cd3 commit 8967a8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions NootedRed/ATOMBIOS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ struct ATOMCommonTableHeader {
constexpr UInt32 ATOM_ROM_TABLE_PTR = 0x48;
constexpr UInt32 ATOM_ROM_DATA_PTR = 0x20;

struct AtomFirmwareInfo : public ATOMCommonTableHeader {
UInt32 firmwareRevision;
UInt32 bootupSclkIn10Khz;
UInt32 bootupMclkIn10Khz;
UInt32 firmwareCapability;
UInt32 mainCallParserEntry;
UInt32 biosScratchRegStartAddr;
};

struct IGPSystemInfoV11 : public ATOMCommonTableHeader {
UInt32 vbiosMisc;
UInt32 gpuCapInfo;
Expand Down
10 changes: 10 additions & 0 deletions NootedRed/X6000FB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! See LICENSE for details.

#include "X6000FB.hpp"
#include "ATOMBIOS.hpp"
#include "NRed.hpp"
#include "PatcherPlus.hpp"
#include <Headers/kern_api.hpp>
Expand Down Expand Up @@ -182,6 +183,9 @@ bool X6000FB::processKext(KernelPatcher &patcher, size_t id, mach_vm_address_t s
MachInfo::setKernelWriting(false, KernelPatcher::kernelWriteLock);
DBGLOG("X6000FB", "Applied DDI Caps patches");

this->biosScratchReg = NRed::callback->getVBIOSDataTable<AtomFirmwareInfo>(0x4)->biosScratchRegStartAddr;
DBGLOG("X6000FB", "BIOS Scratch Reg = 0x%X", this->biosScratchReg);

return true;
}

Expand Down Expand Up @@ -337,10 +341,16 @@ IOReturn X6000FB::wrapSetAttributeForConnection(IOService *framebuffer, IOIndex
//! dc_link_set_backlight_level_nits doesn't print the new backlight level, so we'll do it
DBGLOG("X6000FB", "setAttributeForConnection: New AUX brightness: %d millinits (%d nits)", auxValue,
(auxValue / 1000));
//! Save the brightness value so the driver can restore it on its own on some specific occasions.
//! For instance, when waking from sleep.
NRed::callback->writeReg32(callback->biosScratchReg + 2, auxValue);
success =
callback->orgDcLinkSetBacklightLevelNits(callback->embeddedPanelLink, callback->isHDR, auxValue, 15000);
} else {
UInt32 pwmValue = percentage >= 100 ? 0x1FF00 : ((percentage * 0xFF) / 100) << 8U;
DBGLOG("X6000FB", "setAttributeForConnection: New PWM brightness: 0x%X", pwmValue);
//! Ditto.
NRed::callback->writeReg32(callback->biosScratchReg + 2, pwmValue);
success = callback->orgDcLinkSetBacklightLevel(callback->embeddedPanelLink, pwmValue, 0);
}

Expand Down
1 change: 1 addition & 0 deletions NootedRed/X6000FB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class X6000FB {

private:
mach_vm_address_t orgSetAttributeForConnection {0}, orgGetAttributeForConnection {0};
UInt32 biosScratchReg {0};
UInt32 curPwmBacklightLvl {0}, maxPwmBacklightLvl {0xFFFF};
UInt32 maxOLED {1000 * 512};
void *embeddedPanelLink {nullptr};
Expand Down

0 comments on commit 8967a8d

Please sign in to comment.