Skip to content

Instantly share code, notes, and snippets.

@klausenbusk
Created February 18, 2020 23:16
Show Gist options
  • Save klausenbusk/643f15320ae8997427155c38be13e445 to your computer and use it in GitHub Desktop.
Save klausenbusk/643f15320ae8997427155c38be13e445 to your computer and use it in GitHub Desktop.
See https://github.com/linrunner/TLP/issues/321#issuecomment-587184825 for context..
@surajrv6
Copy link

@userofryzen,
Okay, i will test now and let you know in an hour..

@surajrv6
Copy link

I set the charging limit to 80% when the battery was 74%. here is the reading using upower as soon as battery reached 79% (charging stopped)
Please note that the laptop is pluged in all the time during the test

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 20:21:00 2020 (27 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              33.5654 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         26.0208 W
    voltage:             3.889 V
    time to full:        20.0 minutes
    percentage:          79%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1590331860	79.000	charging
    1590331823	78.000	charging
  History (rate):
    1590331860	26.021	charging
    1590331823	27.294	charging

Here is the reading after 30 minutes

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:07:00 2020 (102 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              33.5654 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         29.5721 W
    voltage:             3.802 V
    time to full:        17.5 minutes
    percentage:          79%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'

After another 30 minutes, here is the upower reading

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:31:00 2020 (32 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              33.5654 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         29.5721 W
    voltage:             3.801 V
    time to full:        17.5 minutes
    percentage:          79%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'

After that I tried setting the threshold to 100. Below is the result as soon as I set the treshold

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:33:25 2020 (54 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              33.5654 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         0.035037 W
    voltage:             3.804 V
    percentage:          79%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (rate):
    1590336205	0.035	charging

Just to make sure the upower reading is correct, I restarted the laptop after 2 minutes and went in bios to check the battery. The battery was 82%

Here is the upower reading after restart

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:35:48 2020 (101 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              34.6516 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         24.0704 W
    voltage:             3.98 V
    time to full:        18.9 minutes
    percentage:          82%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1590336348	0.000	unknown
  History (rate):
    1590336348	0.000	unknown

After 15 min, I checked the upower reading again..

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:49:49 2020 (72 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              38.4706 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         12.0644 W
    voltage:             3.991 V
    time to full:        18.6 minutes
    percentage:          91%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1590337189	91.000	charging
  History (rate):
    1590337189	12.064	charging

after recording the result I restarted the laptop and checked the battery reading in bios. It was 92% (same as the reading)

Here is the result recorded as soon as the restart

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 21:52:54 2020 (73 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              39.0429 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         10.5812 W
    voltage:             3.992 V
    time to full:        18.0 minutes
    percentage:          92%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1590337374	0.000	unknown
  History (rate):
    1590337374	0.000	unknown

I checked the result again in 30 min when the laptop battery indicator was turned white (means charge is full or charging is stopped)

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 22:20:54 2020 (37 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              41.7875 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         3.32851 W
    voltage:             3.998 V
    time to full:        7.8 minutes
    percentage:          98%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (rate):
    1590339054	3.329	charging

I went in bios again to check the battery. it was showing 99%

@surajrv6
Copy link

Here is after battery fully charged

[suraj@asus Desktop]$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               ASUS
  model:                A32-K55
  power supply:         yes
  updated:              Sun May 24 22:31:51 2020 (30 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    energy:              42.0678 Wh
    energy-empty:        0 Wh
    energy-full:         42.2196 Wh
    energy-full-design:  48.0007 Wh
    energy-rate:         2.31244 W
    voltage:             3.984 V
    percentage:          100%
    capacity:            87.9562%
    technology:          lithium-ion
    icon-name:          'battery-full-charged-symbolic'

@userofryzen
Copy link

okey, thank you! here we have the tests so.. kristian, can you send the pach upstream?

@userofryzen
Copy link

@klausenbusk
Have you send the patches to Linux? or havent you time for this cause of exams or work?
I ask because the user surakrv6

@surajrv6
Copy link

I have been also checking the source code to see if changes have been added for the past couple of weeks :)

Here..
https://github.com/torvalds/linux/blob/master/drivers/platform/x86/asus-wmi.c

@userofryzen
Copy link

@klausenbusk are you here?
Is there any news about this? or can't you do it now?
May be this thread have been missed by you for lost time or Idk.

@klausenbusk
Copy link
Author

Hi @userofryzen. I haven't got time to look at it and I don't like just adding every "battery name" (it is a "temporary" solution, we need a permanent solution).

@userofryzen
Copy link

okey, have you something on mind?
I think a recursive function that looks in every BAT x being x letters and numbers?
I don't know if it's efficient or not etc.. I hope someone can solves it

@klausenbusk
Copy link
Author

Someone beat me to it: torvalds/linux@9a33e37

@surajrv6
Copy link

Glad to hear it's implemented finally :)

@egnappahz
Copy link

It's going to become a loooong list if they keep those batterynames coming..

@linrunner
Copy link

linrunner commented Sep 3, 2020

Hi,

for a proper implementation in TLP i need answers to the following questions:

  1. What are the valid values / the range for charge_control_end_threshold?
  2. May i assume that the threshold works exactly the same way – values, range, charge behaviour – for all ASUS laptops that expose /sys/class/power_supply/BAT0/charge_control_end_threshold?
    2a. If not, how do I distinguish the variants e.g. in /sys/class/dmi/id/*
  3. How do i check that asus_wmi is loaded – does /sys/module/asus_wmi exist?
  4. Is the battery always named BATx or else?

@klausenbusk
Copy link
Author

klausenbusk commented Sep 3, 2020

Hi

for a proper implementation in TLP i need answers to the following questions:

Is there any issue I can track?

What are the valid values / the range for charge_control_end_threshold?

0-100, but there is one report of it only supporting 60, 80 and 100.

May i assume that the threshold works exactly the same way – values, range, charge behaviour – for all ASUS laptops that expose /sys/class/power_supply/BAT0/charge_control_end_threshold?

I don't know, but probably (if you ignore that one report).

How do i check that asus_wmi is loaded – does /sys/module/asus_wmi exist?

/sys/module/asus_wmi does indeed exists.

Is the battery always named BATx or else?

The code is currently hard-coded to only create charge_control_end_threshold if the battery name is BAT0, BAT1 or BATT.

@linrunner
Copy link

Is there any issue I can track?

Well, yes ... here you are. I added another question there.

@linrunner
Copy link

The wait is over: the stop charge threshold is implemented for TLP 1.4.

Please participate in the alpha test. All necessary information is here.

Have fun.

@therealak12
Copy link

therealak12 commented Aug 10, 2024

Asus UX3404VA supports only 60, 80, and 100 in the /sys/class/power_supply/BAT0/charge_control_end_threshold file (as reported above).

Does anyone know that this is a hardware or software limitation? Do you have any workarounds to bypass it?

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