Skip to content

Instantly share code, notes, and snippets.

@linrunner
Last active September 26, 2023 18:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linrunner/b7e4454f91d1f8be4ee126b7da7379f2 to your computer and use it in GitHub Desktop.
Save linrunner/b7e4454f91d1f8be4ee126b7da7379f2 to your computer and use it in GitHub Desktop.

TLP 1.4 Test: Battery Care for ASUS Laptops

Read the overview document first.

Supported Features

ASUS laptops using the asus_wmi driver have a stop charge threshold ranging from 0% (threshold off) to 100%. The hardware behaviour is:

  1. Connected to the charger, charging stops when the charge level reaches the stop threshold

  2. If the charge level is higher than the stop threshold, the battery will not discharge automatically; it will only be discharged when the charger is removed i.e. the laptop runs on battery

When suitable hardware has been detected, tlp-stat -b shows:

+++ Battery Care
Plugin: asus
Supported features: charge threshold
Driver usage:
* natacpi (asus_wmi) = active (charge threshold)
Parameter value range:
* STOP_CHARGE_THRESH_BAT0/1: 0(off)..100(default)

+++ Battery Status: BAT0
...
/sys/class/power_supply/BAT0/charge_control_end_threshold   =    100 [%]
...

How it works

Battery charging is a process not controlled by TLP itself, but by the laptop's embedded controller (EC). This makes the process work even when switched off or no operating system is running. You cannot change the basic behavior, it is hard-coded into the EC firmware by the vendor. TLP just writes the charge threshold into the EC with the help of the kernel driver, the EC takes care of the rest.

Installation

Packages are provided at the download page.

Linux kernel 5.4 or higher required.

Test Cases

Important: please provide all terminal input and output from the test cases via an individual Gist and link it in your post below.

1. Configure and apply a charge stop threshold

Edit /etc/tlp.conf (or a config file of your choice under /etc/tlp.d/):

STOP_CHARGE_THRESH_BAT0="80"

Note: if necessary replace with your own value that suits the test case.

Enter the following commands in a terminal (as root or with sudo):

tlp start
tlp-stat -s -c -b

Verify that charge_control_end_threshold = 80.

2. Verify the charging process

  1. Let the laptop run on battery power until the charge level falls below the stop threshold by at least 10%
  2. Connect the charger and see if charging starts
  3. Verify that charging stops at 80% (or your configured value)

Enter the command (as root or with sudo):

tlp-stat -b

3. Change charge stop threshold manually

Enter the commands (as root or with sudo):

tlp setcharge 0 85
tlp-stat -b

Verify that charge_control_end_threshold = 85 and charging starts.

Notes:

  • If necessary replace 85 with a value higher than your first value chosen above
  • The first command argument '0' is a dummy for the start threshold not available on ASUS laptops

Enter the commands (as root or with sudo):

tlp setcharge
tlp-stat -b

Verify that charge_control_end_threshold = 80 and charging halts.

4. Disable stop threshold and return to full charge

Edit the config file used above and comment the parameter to disable it:

#STOP_CHARGE_THRESH_BAT0="80"

Enter the commands (as root or with sudo):

tlp fullcharge
tlp-stat -b

Verify that charge_control_end_threshold = 100 and the battery gets fully charged.

What else should I check?

  • A user has reported an ASUS laptop recognizing only discrete values 60, 80, 100; other values just being ignored by the hardware - can other users confirm this?
  • Are there ASUS laptops with more than one battery (tlp-stat -b should show)?
@OdinVex
Copy link

OdinVex commented Jul 22, 2021

@linrunner
Copy link
Author

@OdinVex: you did not use version 1.4, with 1.3.1 it does not work. Please read the instructions at the top.

@OdinVex
Copy link

OdinVex commented Jul 22, 2021

@OdinVex: you did not use version 1.4, with 1.3.1 it does not work. Please read the instructions at the top.

My bad, long frustrating day. Shortly after installing tlp and taking that first gist, the battery is now stuck at 0 and the laptop won't even run on it anymore. Even a dual-boot to another OS, BIOS reset, reset of pins, etc. Same (new) battery. Updated the gist with 1.4.

@linrunner
Copy link
Author

@OdinVex: outputs are still 1.3.1. With defective hardware the tests don't make sense. Sorry, i can feel your frustration.

@OdinVex
Copy link

OdinVex commented Jul 22, 2021

@OdinVex: outputs are still 1.3.1. With defective hardware the tests don't make sense. Sorry, i can feel your frustration.

I found out what was wrong with this battery. It is a new replacement for a 'nearly exploded' battery. After I ran tlp and gave you the first 1.3 numbers, one of the cold-soldered joints of one of the wires in the battery popped off. I could've returned it, but I took the time to just open it up, reverse-engineer it. Re-soldered, live and well again. As for the gist, the second revision onward have all been 1.4, GitHub simply didn't paste correctly from clipboard and I neglected to check. Fixed now and laptop is tested but no-go on charging limit. I'm using the TLP 1.4.0-alpha.2 debs. This is for a GL702ZC.

@linrunner
Copy link
Author

@OdinVex: the kernel does not provide charge_control_end_threshold, so your hardware is not supported

@OdinVex
Copy link

OdinVex commented Jul 22, 2021

@OdinVex: the kernel does not provide charge_control_end_threshold, so your hardware is not supported

Thank you for clarifying. I do wish ASUS was a bit more open with their hardware.

@linrunner
Copy link
Author

@OdinVex: the head of the output states the vendor, the driver and the reason

+++ Battery Care
Plugin: asus
Supported features: none available
Driver usage:

  • natacpi (asus_wmi) = inactive (laptop not supported)

Would you phrase it differently? If so, how?

@OdinVex
Copy link

OdinVex commented Jul 22, 2021

none available

The output was obvious, just wishing ASUS was more open with their hardware, so we could write drivers without needing to black-box it all.. >_>

@linrunner
Copy link
Author

Beta 2 is out. Enjoy!

@linrunner
Copy link
Author

linrunner commented Sep 24, 2021

TLP 1.4 is released. Have fun and please keep testing!

@foxhoundsk
Copy link

Hi @linrunner, does /sys/class/power_supply/BAT0/charge_control_start_threshold not presenting means that the kernel (corresponding driver) can't recognize the EC so that it can't modify the threshold? Is it possible that the threshold is not modifiable for specific model?

I'm curious about the chance that we can reverse-engineer the EC to figure the way to set the threshold.

My laptop is ASUS X550JX, which is a circa 7-year-old model.

The output of TLP says:
https://gist.github.com/foxhoundsk/fcedcea96cd9e238ba7092f68643887b

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment