Skip to content

Instantly share code, notes, and snippets.

@linrunner
Last active February 28, 2024 17:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linrunner/fee8feeb079efc03001d9f3671146298 to your computer and use it in GitHub Desktop.
Save linrunner/fee8feeb079efc03001d9f3671146298 to your computer and use it in GitHub Desktop.

TLP 1.4 Test: Battery Care for LG Gram Laptops

Read the overview document first.

Supported Features

LG Gram laptops using the lg_laptop driver have a feature called 'battery care limit', basically a fixed stop charge threshold at 80%. 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: lg
Supported features: charge threshold
Driver usage:
* vendor (lg_laptop) = active (charge threshold)
Parameter value range:
* STOP_CHARGE_THRESH_BAT0: 80(on), 100(off) -- battery care limit

/sys/devices/platform/lg-laptop/battery_care_limit          = 80 [%]

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 4.20 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 enable battery care limit

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

STOP_CHARGE_THRESH_BAT0="80"

Connect the charger.

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

tlp start
tlp-stat -s -c -b

Verify that battery_care_limit = 80.

2. Verify the charging process

  1. Let the laptop run on battery power until the charge level falls below at least 70%
  2. Connect the charger and see if charging starts
  3. Verify that charging stops at 80%

Enter the command (as root or with sudo):

tlp-stat -b

3. Disable battery care limit and return to full charge

Edit the config file used above:

STOP_CHARGE_THRESH_BAT0="100"

Enter the commands (as root or with sudo):

tlp fullcharge
tlp-stat -b

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

What else should I check?

  • Are there LG Gram laptops with more than one battery (tlp-stat -b should show)?
@atkiss
Copy link

atkiss commented Sep 11, 2021

Hope this helps. If you need any additional info pls let me know.

root@neon:~# tlp noop
Debug: no operation performed.
root@neon:~# tlp-stat -T
--- TLP 1.4.0-beta.2 --------------------------------------------

-- Logs begin at Sat 2021-09-11 19:57:36 UTC, end at Sat 2021-09-11 20:57:32 UTC. --
Sep 11 20:05:46 neon tlp[3731]: +++ noop (1.4.0-beta.2) ++++++++++++++++++++++++++++++++++++++++
Sep 11 20:05:46 neon tlp[3731]: get_sys_power_supply(ADP1).ac_online: syspwr=0
Sep 11 20:05:46 neon tlp[3731]: power_source=ac
Sep 11 20:05:46 neon tlp[3731]: manual_mode=none
Sep 11 20:05:46 neon tlp[3731]: power_mode=ac
Sep 11 20:05:46 neon tlp[3731]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.thinkpad.not_a_thinkpad
Sep 11 20:05:46 neon tlp[3731]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.thinkpad-legacy.not_a_thinkpad
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.asus.no_match
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.huawei.no_match
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.lenovo.no_match
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.samsung.no_match
Sep 11 20:05:46 neon tlp[3731]: batdrv_init.lg: batteries=CMB0; natacpi=254; thresh=none; bf_stop=
Sep 11 20:05:46 neon tlp[3731]: batdrv.lg.select_battery(DEF): bat_str=CMB0; bd_read=/sys/class/power_supply/CMB0;
Sep 11 20:05:46 neon tlp[3731]: save_runconf.ok: /run/tlp/tlp-run.conf_tmpR8u5K8 -> /run/tlp/run.conf
root@neon:~# ls -l /sys/devices/platform/lg-laptop/
total 0
-rw-r--r-- 1 root root 4096 Sep 11 20:02 battery_care_limit
lrwxrwxrwx 1 root root    0 Sep 11  2021 driver -> ../../../bus/platform/drivers/lg-laptop
-rw-r--r-- 1 root root 4096 Sep 11 20:08 driver_override
-rw-r--r-- 1 root root 4096 Sep 11 20:08 fan_mode
-rw-r--r-- 1 root root 4096 Sep 11 20:08 fn_lock
drwxr-xr-x 4 root root    0 Sep 11  2021 leds
-r--r--r-- 1 root root 4096 Sep 11 20:08 modalias
drwxr-xr-x 2 root root    0 Sep 11 20:08 power
-rw-r--r-- 1 root root 4096 Sep 11 20:08 reader_mode
lrwxrwxrwx 1 root root    0 Sep 11  2021 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Sep 11  2021 uevent
-rw-r--r-- 1 root root 4096 Sep 11 20:08 usb_charge
root@neon:~# ls -l /sys/class/power_supply/CMB0/
total 0
-rw-r--r-- 1 root root 4096 Sep 11 20:08 alarm
-r--r--r-- 1 root root 4096 Sep 11  2021 capacity
-r--r--r-- 1 root root 4096 Sep 11 20:08 capacity_level
-r--r--r-- 1 root root 4096 Sep 11 20:02 cycle_count
lrwxrwxrwx 1 root root    0 Sep 11 20:08 device -> ../../../PNP0C0A:00
-r--r--r-- 1 root root 4096 Sep 11  2021 energy_full
-r--r--r-- 1 root root 4096 Sep 11  2021 energy_full_design
-r--r--r-- 1 root root 4096 Sep 11  2021 energy_now
drwxr-xr-x 3 root root    0 Sep 11  2021 hwmon2
-r--r--r-- 1 root root 4096 Sep 11  2021 manufacturer
-r--r--r-- 1 root root 4096 Sep 11  2021 model_name
drwxr-xr-x 2 root root    0 Sep 11 20:08 power
-r--r--r-- 1 root root 4096 Sep 11  2021 power_now
-r--r--r-- 1 root root 4096 Sep 11  2021 present
-r--r--r-- 1 root root 4096 Sep 11  2021 serial_number
-r--r--r-- 1 root root 4096 Sep 11  2021 status
lrwxrwxrwx 1 root root    0 Sep 11  2021 subsystem -> ../../../../../../../../../class/power_supply
-r--r--r-- 1 root root 4096 Sep 11  2021 technology
-r--r--r-- 1 root root 4096 Sep 11  2021 type
-rw-r--r-- 1 root root 4096 Sep 11  2021 uevent
-r--r--r-- 1 root root 4096 Sep 11  2021 voltage_min_design
-r--r--r-- 1 root root 4096 Sep 11  2021 voltage_now

@linrunner
Copy link
Author

@atkiss : looks normal so far. Now lets check your use case:

sudo tlp start
sudo tlp-stat -T 

@atkiss
Copy link

atkiss commented Sep 13, 2021

@linrunner here we go:

root@neon:~# sudo tlp start
Error: could not read current care limit. Skipped.
TLP started in AC mode (auto).
root@neon:~# sudo tlp-stat -T
--- TLP 1.4.0-beta.2 --------------------------------------------

-- Logs begin at Sun 2021-09-12 20:53:45 UTC, end at Sun 2021-09-12 21:53:46 UTC. --
Sep 12 20:59:06 neon tlp[4151]: +++ noop (1.4.0-beta.2) ++++++++++++++++++++++++++++++++++++++++
Sep 12 20:59:06 neon tlp[4151]: get_sys_power_supply(ADP1).ac_online: syspwr=0
Sep 12 20:59:06 neon tlp[4151]: power_source=ac
Sep 12 20:59:06 neon tlp[4151]: manual_mode=none
Sep 12 20:59:06 neon tlp[4151]: power_mode=ac
Sep 12 20:59:06 neon tlp[4151]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.thinkpad.not_a_thinkpad
Sep 12 20:59:06 neon tlp[4151]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.thinkpad-legacy.not_a_thinkpad
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.asus.no_match
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.huawei.no_match
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.lenovo.no_match
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.samsung.no_match
Sep 12 20:59:06 neon tlp[4151]: batdrv_init.lg: batteries=CMB0; natacpi=254; thresh=none; bf_stop=
Sep 12 20:59:06 neon tlp[4151]: batdrv.lg.select_battery(DEF): bat_str=CMB0; bd_read=/sys/class/power_supply/CMB0;
Sep 12 20:59:06 neon tlp[4151]: save_runconf.ok: /run/tlp/tlp-run.conf_tmpa2ZLIE -> /run/tlp/run.conf
Sep 12 21:00:01 neon tlp[4230]: +++ start (1.4.0-beta.2) ++++++++++++++++++++++++++++++++++++++++
Sep 12 21:00:01 neon tlp[4230]: get_sys_power_supply(ADP1).ac_online: syspwr=0
Sep 12 21:00:01 neon tlp[4230]: power_source=ac
Sep 12 21:00:01 neon tlp[4230]: manual_mode=none
Sep 12 21:00:01 neon tlp[4230]: power_mode=ac
Sep 12 21:00:01 neon tlp[4230]: compare_and_save_power_state(0).different: old=
Sep 12 21:00:02 neon tlp[4230]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.thinkpad.not_a_thinkpad
Sep 12 21:00:02 neon tlp[4230]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.thinkpad-legacy.not_a_thinkpad
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.asus.no_match
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.huawei.no_match
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.lenovo.no_match
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.samsung.no_match
Sep 12 21:00:02 neon tlp[4230]: batdrv_init.lg: batteries=CMB0; natacpi=254; thresh=none; bf_stop=
Sep 12 21:00:02 neon tlp[4230]: batdrv.lg.read_threshold: bf_stop=; out=; rc=255
Sep 12 21:00:02 neon tlp[4230]: batdrv.lg.write_thresholds(80, 1, BAT0).read_error
Sep 12 21:00:02 neon tlp[4230]: save_runconf.ok: /run/tlp/tlp-run.conf_tmp9JPVnq -> /run/tlp/run.conf
root@neon:~# 

@linrunner
Copy link
Author

@atkiss : the problem is not only related to the LG plugin. Thanks for reporting.

Now fixed: linrunner/TLP@c2646f6

Package download:

Please test again:

sudo tlp start
sudo tlp-stat -T 

@atkiss
Copy link

atkiss commented Sep 14, 2021

@linrunner This is the result of the commands with the new version:

root@neon:~# tlp start
TLP started in battery mode (auto).
root@neon:~# tlp-stat -T
--- TLP 1.4.0-beta.2 --------------------------------------------

-- Logs begin at Mon 2021-09-13 22:43:45 UTC, end at Mon 2021-09-13 23:43:45 UTC. --
Sep 13 22:48:27 neon tlp[3578]: +++ start (1.4.0-beta.2) ++++++++++++++++++++++++++++++++++++++++
Sep 13 22:48:27 neon tlp[3578]: get_sys_power_supply(ADP1).ac_offline: syspwr=1
Sep 13 22:48:27 neon tlp[3578]: power_source=bat
Sep 13 22:48:27 neon tlp[3578]: manual_mode=none
Sep 13 22:48:27 neon tlp[3578]: power_mode=bat
Sep 13 22:48:27 neon tlp[3578]: compare_and_save_power_state(1).different: old=
Sep 13 22:48:27 neon tlp[3578]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.thinkpad.not_a_thinkpad
Sep 13 22:48:27 neon tlp[3578]: check_thinkpad.not_a_thinkpad: model=0.1
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.thinkpad-legacy.not_a_thinkpad
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.asus.no_match
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.huawei.no_match
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.lenovo.no_match
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.samsung.no_match
Sep 13 22:48:27 neon tlp[3578]: batdrv_init.lg: batteries=CMB0; natacpi=254; thresh=none; bf_stop=
Sep 13 22:48:27 neon tlp[3578]: set_charge_thresholds.no_method
Sep 13 22:48:27 neon tlp[3578]: save_runconf.ok: /run/tlp/tlp-run.conf_tmpgeWCoU -> /run/tlp/run.conf

root@neon:~# tlp-stat -b
--- TLP 1.4.0-beta.2 --------------------------------------------

+++ Battery Care
Plugin: lg
Supported features: none available
Driver usage:
* vendor (lg_laptop) = inactive (laptop not supported)

+++ Battery Status: CMB0
/sys/class/power_supply/CMB0/manufacturer                   =  LG  
/sys/class/power_supply/CMB0/model_name                     = LGC-LGC
/sys/class/power_supply/CMB0/cycle_count                    =     18
/sys/class/power_supply/CMB0/energy_full_design             =  80000 [mWh]
/sys/class/power_supply/CMB0/energy_full                    =  75750 [mWh]
/sys/class/power_supply/CMB0/energy_now                     =  49000 [mWh]
/sys/class/power_supply/CMB0/power_now                      =   8537 [mW]
/sys/class/power_supply/CMB0/status                         = Discharging

Charge                                                      =   64.7 [%]
Capacity                                                    =   94.7 [%]

@linrunner
Copy link
Author

@atkiss : results are as expected now 👍

@atkiss
Copy link

atkiss commented Sep 16, 2021

Sorry @linrunner I'm confused now. So does this mean that the battery care is not supported on my laptop?

+++ Battery Care
Plugin: lg
Supported features: none available
Driver usage:
* vendor (lg_laptop) = inactive (laptop not supported)

@linrunner
Copy link
Author

linrunner commented Sep 17, 2021

Exactly. The kernel driver must be adapted, please join the discussion here: linrunner/TLP#568 (comment)

@atkiss
Copy link

atkiss commented Sep 17, 2021

Exactly. The kernel driver must be adapted, please join the discussion here: linrunner/TLP#568 (comment)

Ah I see, thanks for all your effort anyway!

@linrunner
Copy link
Author

TLP 1.4 is released. Have fun!

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