aymanbagabas / Huawei-WMI

Huawei WMI laptop extras linux driver
GNU General Public License v2.0
229 stars 15 forks source link

Help with understanding the battery thresholds feature #46

Closed ldan93 closed 3 years ago

ldan93 commented 3 years ago

Hello,

I'm trying to implement the battery thresholds feature under MacOS (hackintosh) on the Matebook X Pro 2018 (MACH-WX9). I'm trying to do this only by using ACPI calls.

From reading your code and the DSDT of this machine, I understand that the \GBTT and \SBTT ACPI methods are responsible for getting and setting min/max battery thresholds :

Capture d’écran 2020-12-30 à 15 20 39

I've used this line of the SBTT method to try to set the threshold to 60/75 (3C/4B) : \_SB.PCI0.LPCB.EC0.ECXT (0xC7, One, 0x3C, 0x4B, Zero, Zero)

From both MacOS and Linux (via acpi_call), this ACPI call doesn't seem to be effective : the battery is still charging between 60 and 75%. So I guess this isn't enough / there is something I don't really understand.

Do you have any idea what would be the ACPI call(s) equivalent to the following command ? echo "60 75" | sudo tee /sys/devices/platform/huawei-wmi/charge_control_thresholds

Thank you very much !

aymanbagabas commented 3 years ago

Hi @ldan93,

The line you used to set the threshold should theoretically be effective. You can verify that by looking at EC memory, I use RWEverything in Windows and modprobe ec_sys && watch -n1 hexdump -Cv /sys/kernel/debug/ec/ec0/io in Linux. Also if you want to debug ACPI, I'd recommend using acpiexec to run a sandboxed ACPI environment where you can test these functions.

Now these two functions expect one argument in little-endian, the first two bytes are reserved for HWMI (Huawei WMI) interface and the other two are the arguments that these functions take and operate on. So if you want to set the thresholds to 60/70 you would call \SBTT 0x4b3c0000. If you were using WMI, the first two bytes would be 0x1003 because that's the HWMI identifier that maps to \SBTT and the WMI would call \SBTT 0x4b3c1003 in that case so these first two bytes really don't matter if you're using ACPI directly instead of WMI.

I found this cool project https://github.com/the-darkvoid/macOS-IOElectrify that implements ACPI WMI for MacOS I thought it would be very helpful to the Hackintosh community. It would be awesome to fork/extend that to support more devices. Look at https://github.com/torvalds/linux/blob/master/drivers/platform/x86/wmi.c if you're more interested in this topic.

ldan93 commented 3 years ago

Thank you very much for all your useful explanations and advice ! Calling \SBTT with the syntax you explained works under MacOS. I will have a thorough look at the projects you mentioned.