Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume from hibernation turns off battery threshold at 80 percent #103

Open
whatnameisit opened this issue Sep 19, 2021 · 6 comments
Open

Comments

@whatnameisit
Copy link

whatnameisit commented Sep 19, 2021

On normal use, AsusSMC 1.4.0+ caps the battery level at 80 percent if Battery Health in Energy Saver is toggled on.
When the machine resumes from hibernation, the threshold is ignored and the battery keeps on charging until 100 percent.
I'm not good with logging (and about zero knowledge in coding), so if anyone could tell me how, I'll collect the logs and upload them here.

IOReg: Battery Conservation Mode is marked true in ATK-AsusSMC
MacBook Pro.zip
Asus Dmesg output shows battery conservation mode true
Asus.log.zip
Hibernation logs Hibern hibern HBFX
hibernation.zip

@Ubsefor
Copy link
Contributor

Ubsefor commented Sep 19, 2021

This feature shouldn't work at all on non-apple hardware. I tried to use it for a bit and noticed that my battery doesn't charge correctly with this turned on: battery dies at 30-40% immediately.

I don't know whether you have the same issue or not, but I suggest at least checking it out.

@whatnameisit
Copy link
Author

I'm not sure we are on the same issue. By "this feature," did you mean battery threshold on hibernation or just the battery threshold?
Hibernation works with HibernationFixup.kext and battery threshold works with AsusSMC.kext.
When both kexts are used together, battery threshold is ignored when resuming from hibernation. A simple reboot makes the limit to kick in and prevent the charging above 80 percent again.
I don't remember experiencing the laptop shutting down at 30-40 percent battery level, if that's what you mean by battery dies at 30-40% immediately. I'm pretty sure there were times the battery level was below 25 percent and it charged fine with the battery threshold feature on.
Since you commented, do you know how to debug or collect logs on my issue?

Nevuly added a commit to Nevuly/S510UA-BQ423-Hackintosh that referenced this issue Oct 12, 2021
…number

 * HibernationFixup breaks battery threshold in AsusSMC.
 * Sometimes laptop suddenly stopped to powering on, that issue may came from hibernation.
 * Remove HibernationFixup kext and configs to avoid this issue.
 * Issue thread in AsusSMC(hieplpvip/AsusSMC#103).
 * Add Update type and Revision number to management versions.

Bug: R8EU-001
Test: Apply and Reboot

Signed-off-by: Yang Jeong Hun <[email protected]>
@whatnameisit
Copy link
Author

I fried my laptop's motherboard and sold it for 100000 won. I won't close this issue though because it's a real one.

@yjmd2222
Copy link

1.4.0
Support battery charge threshold found on new laptops (charging stops at 80%). Can be disabled by turning off Battery Health in Energy Saver.

Can it really be turned off in Energy Saver in Catalina?

AsusSMC/AsusSMC/AsusSMC.cpp

Lines 379 to 390 in c15d2f2

void AsusSMC::initBattery() {
// Battery Health was introduced in 10.15.5
// Check if we're on 10.15.5+
if (getKernelVersion() < KernelVersion::Catalina || (getKernelVersion() == KernelVersion::Catalina && getKernelMinorVersion() < 5)) {
return;
}
isBatteryRSOCAvailable = wmi_dev_is_present(ASUS_WMI_DEVID_RSOC);
if (isBatteryRSOCAvailable) {
toggleBatteryConservativeMode(true);
}
}

AsusSMC/AsusSMC/AsusSMC.cpp

Lines 604 to 616 in c15d2f2

void AsusSMC::toggleBatteryConservativeMode(bool state) {
if (!isBatteryRSOCAvailable) {
DBGLOG("batt", "RSOC unavailable");
return;
}
if (wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, ASUS_WMI_DEVID_RSOC, state ? 80 : 100) != 1) {
SYSLOG("batt", "Failed to %s battery conservative mode", state ? "enable" : "disable");
} else {
DBGLOG("batt", "Battery conservative mode is %s", state ? "enabled" : "disabled");
setProperty("BatteryConservativeMode", state);
}
}

AsusSMC/AsusSMC/AsusSMC.cpp

Lines 871 to 875 in c15d2f2

if (isBatteryRSOCAvailable) {
VirtualSMCAPI::addKey(KeyBDVT, vsmcPlugin.data, VirtualSMCAPI::valueWithFlag(
false, new BDVT(this),
SMC_KEY_ATTRIBUTE_READ | SMC_KEY_ATTRIBUTE_WRITE | SMC_KEY_ATTRIBUTE_ATOMIC));
}

I don't see any reading from Battery Health that is used to turn it off.

Anyways, I think the original issue can be resolved if the kext calls the method on resume. I don't know the details, but hibernation is similar to shutdown, which if true will reset EC to original, non-conservation mode. A quick check is to call the corresponding ACPI method EC0.SRSC (0) on resume with ACPIDebug.kext.

@yjmd2222
Copy link

yjmd2222 commented Aug 3, 2024

I'm blind

SMC_RESULT BDVT::update(const SMC_DATA *src) {
bool state = false;
lilu_os_memcpy(&state, src, size);
// BDVT is 00 when battery health is enabled and 01 when disabled
state = !state;
AsusSMC *drv = OSDynamicCast(AsusSMC, dst);
drv->toggleBatteryConservativeMode(state);
lilu_os_memcpy(data, src, size);
return SmcSuccess;
}

I can't get the machine to hibernate, so can't test it. Tried: HibernateMode=Auto/RTC/NVRAM, ThirdPartyDrives=True, HibernationFixup.kext=enabled, and hibernatemode=25/3.
If anyone has step-by-step directions to enable hibernation, please share, because I might have missed something.

@yjmd2222
Copy link

yjmd2222 commented Aug 7, 2024

Upon resume from hibernation, the battery does charge above the threshold. Then I set the threshold with ACPIDebug.

[ 1267.932184]: [ACPI Debug]  [ACPI Debug]  "Setting SRSC = 80"

And the battery stops charging.
스크린샷 2024-08-08 오전 1 13 14
The icon shows AC is plugged in and not charging.

The kext code can be updated to send battery health command on resume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants