Skip to content

Instantly share code, notes, and snippets.

@linrunner
Last active September 24, 2021 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linrunner/2d8eadc217a86d28c1939ac31f434271 to your computer and use it in GitHub Desktop.
Save linrunner/2d8eadc217a86d28c1939ac31f434271 to your computer and use it in GitHub Desktop.

TLP 1.4 Test: Battery Care for Huawei MateBooks

Read the overview document first.

Supported Features

Huawei laptops using the huawei_wmi driver provide both a start and a stop charge threshold ranging from 0% (threshold off) to 100%. The hardware behaviour is:

  1. When connecting the charger, charging starts if the charge level is below the start threshold

  2. Once started, charging stops when the charge level reaches the stop threshold

  3. 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: huawei
Supported features: charge thresholds
Driver usage:
* natacpi (huawei_wmi) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  0(off)..95(default)..100
* STOP_CHARGE_THRESH_BAT0/1:   0(off)..100(default)

+++ Battery Status: BAT0
...
/sys/class/power_supply/BAT0/charge_control_start_threshold =     95 [%]
/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 thresholds

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

START_CHARGE_THRESH_BAT0="70"
STOP_CHARGE_THRESH_BAT0="80"

Note: if necessary replace with your own values that suit the test case.

Connect the charger.

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

tlp start
tlp-stat -s -c -b

Verify that charge_control_start_threshold = 70 and 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 2%
  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 thresholds manually

Enter the commands (as root or with sudo):

tlp setcharge 85 90
tlp-stat -b

Verify that charge_control_start_threshold = 85, charge_control_end_threshold = 90 and charging starts.

Note: if necessary replace with your own values that suit the test case.

Enter the commands (as root or with sudo):

tlp setcharge
tlp-stat -b

Verify thatcharge_control_start_threshold = 70, charge_control_end_threshold = 80 and charging halts.

4. Disable charge thresholds and return to full charge

Edit the config file used above and comment the parameters to disable them:

#START_CHARGE_THRESH_BAT0="70"
#STOP_CHARGE_THRESH_BAT0="80"

Enter the commands (as root or with sudo):

tlp fullcharge
tlp-stat -b

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

What else should I check?

  • Are there Huawei laptops with more than one battery (tlp-stat -b should show)?
@linrunner
Copy link
Author

linrunner commented Sep 24, 2021

TLP 1.4 is released. Have fun and keep testing please1

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