Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery Care for Dell laptops (Kernel 6.12 required) #379

Closed
ghost opened this issue Jan 9, 2019 · 79 comments
Closed

Battery Care for Dell laptops (Kernel 6.12 required) #379

ghost opened this issue Jan 9, 2019 · 79 comments

Comments

@ghost
Copy link

ghost commented Jan 9, 2019

EDIT by @linrunner

The wait is over: an initial version of the Dell plugin is ready to test.
[EDIT] Kernel 6.12 is required.
Testing instructions -> #379 (comment)

===============================================================================================
My understanding is that currently only ThinkPad devices have advanced battery features available, due to the existence of tp_smapi.
For Dell devices there exists the 'Dell Command | Configure' which appears to provide similar functionality in regards to battery management, for example running off AC power and express charging, even though the interface is rather suboptimal.
That's all the more reason to build a tool for it, but the question is if it should be this one.

@linrunner
Copy link
Owner

These are Windows binaries, dear. If you want things moving, implement a kernel interface e.g. driver for your hardware. See: #321

@ghost
Copy link
Author

ghost commented Jan 15, 2019

I'm afraid you are mistaken, there are Linux binaries available as well: https://www.dell.com/support/article/us/en/04/sln311302/dell-command-configure?lang=en

@linrunner
Copy link
Owner

linrunner commented Jan 20, 2019

I see.

--PrimaryBattChargeCfg seems do to charge thresholds. Did you spot something like force_discharge (for recalibration)?

Contras:

  • I didn't see source downloads and there are binary packages for Ubuntu 16.04 and RHEL 6/7 only.
  • I won't call a closed source tool from inside TLP and would still prefer using the generic kernel interface mentioned above.

@linrunner linrunner changed the title advanced battery features for dell devices Advanced battery features for Dell devices Jan 20, 2019
@linrunner
Copy link
Owner

linrunner commented Mar 7, 2019

Yesterday I stumbled over smbios-utils: https://github.com/dell/libsmbios/ Any volunteers to check out and document how to use it? Command line args are a bit cryptic.

ps. I don't have Dell hardware within reach.

@spockfish
Copy link

My daily machine is a Dell XPS running openSUSE with TLP. So what do you exactly need?

@linrunner
Copy link
Owner

linrunner commented Apr 3, 2019

General question: are Dell battery features similar enough to the ThinkPad approach so one can integrate them into the existing TLP commands (setcharge/discharge/recalibrate):

  • What are the exact commands (with binary path) to set the start and stop threshold?
  • Valid ranges for the threshold values/parameters?
  • How to read back actual threshold values from the firmware
  • What is the exact command to check Dell battery features are actually supported on a laptop?
  • Is there a command to discharge a battery while AC is connected?
  • How to select primary / secondary battery in the above commands on Dell laptops (if dual batteries models exist)?

@spockfish
Copy link

Ok. I've got the latest smbios installed. It's shipped with openSUSE, so that's the good news. The bad news is that I get nothing out of it. For example, a 'sudo smbios-battery-ctl --battery-charge' results in this:

Libsmbios version : 2.4.2
smbios-battery-ctl version : 2.4.2
 
 Supported battery charging features: 
         NIL
 
 Battery charging Status: 
         NIL

No difference what so ever with AC plugged in or not. So I'm not sure if this libsmbios is actually bringing something to the table...

@linrunner
Copy link
Owner

Dead end? Just for the record: could you post the output of

tlp-stat -s

@marmistrz
Copy link

marmistrz commented May 26, 2019

As for the first three points: the relevant option is described in the manual here
As for the last two points, I can't find anything that would allow it.

I'm also getting NILs from smbios, I'm going to report it in the libsmbios repository.

In any case, smbios-battery-ctl is pretty low-level could do the trick, but on the other hand, I'm not sure if it wouldn't conflict with the BIOS settings.

$ tlp-stat -s                                                                              
--- TLP 1.2.2 --------------------------------------------

+++ System Info
System         = Dell Inc.  Vostro 3580
BIOS           = 1.0.0
Kernel         = 4.19.45-1-lts #1 SMP Wed May 22 13:02:41 CEST 2019 x86_64
/proc/cmdline  = BOOT_IMAGE=/vmlinuz-linux-lts <mount-related options>
Init system    = systemd 
Boot mode      = UEFI

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 02:29:23,      8 sec(s) ago
Mode           = battery
Power source   = battery

@linrunner
Copy link
Owner

linrunner commented May 28, 2019

Thanks. Just for the record:

cctk --PrimaryBattChargeCfg=Custom:50-70

@marmistrz
Copy link

marmistrz commented May 28, 2019

/remark: the reply was substantially edited

On the other hand, I have second thoughts about introducing a proprietary opt-dependency to tlp.

It appears that smbios already exposes the API using the low-level token API: token_list.csv
Still

# smbios-token-ctl -i 0x0349

prints the token as a bool, which is clearly invalid

================================================================================
  Token: 0x0349 - Primary Battery Custom Charge Start (NA)
  value: bool = false
   Desc: Sets the percentage value at which the battery charging will start Impl
         ementation Note: This field must be in the range [50, 95] with a step v
         alue of 1 and at least 5% less than Primary Custom Charge End

Trying to access the token directly using the Python bindings is weird but feasible - they numeric values are encoded as 2-byte little-endian integers.

# ipython
In [1]: from libsmbios_c import smbios_token                                                                                                                                                  
In [2]: t = smbios_token.TokenTable()  
In [3]: tok = t[0x0349]       
In [7]: tok.getString()                                                                                                                                                                       
Out[7]: b'2\x00'
In [9]: tok.getType()                                                                                                                                                                         
Out[9]: 218
In [10]: tok.isBool()             # What the hell?                                                                                                                                                              
Out[10]: True
In [11]: tok.isString()                                                                                                                                                                       
Out[11]: True 
In [20]: int.from_bytes(tok.getString(), "little")                                                                                                                                      
Out[20]: 50
In [21]: int.from_bytes(t[0x034A].getString(), "little")                                                                                                                                      
Out[21]: 90

Probably the best idea would be to contribute the API to smbios-battery-ctl and only use the shell tool through tlp.

While I can't guarantee code contributions to this one (I'll see what I can do), I can promise I'll test the changes related to power-management on Dell laptops.

For reference, here's the issue about smbios-battery-ctl returning NILs: dell/libsmbios#71

@linrunner
Copy link
Owner

linrunner commented May 29, 2019

However, i'm not going to include code that calls a proprietary tool.

ps. and i would definitely prefer a kernel solution that uses the natacpi framework laid out in #321.

@marmistrz
Copy link

marmistrz commented May 29, 2019

On the other hand, I have second thoughts about introducing a proprietary opt-dependency to tlp.

However, i'm not going to include code that calls a proprietary tool.
ps. and i would definitely prefer a kernel solution that uses the natacpi framework laid out in #321.

What I meant was that cctk is proprietary and that I think it may be a bad idea to depend on it ;) It's great that we agree on this. :)

So we can either use libsmbios (GPL2) or natacpi. It looks like I've already solved the major obstacles, so I think I can extend smbios-battery-ctl to support PrimaryBatteryChargeCfg during the weekend.

I won't be able to help with natacpi in any other way than testing. You may consider contacting the Dell developers. (I'm not affiliated with Dell in any way, I'm just using a laptop produced by the company)

@marmistrz
Copy link

@linrunner let me know if you're ok with this CLI

@marmistrz
Copy link

@linrunner the pull request to dell/libsmbios has been merged. You can now use it to implement tlp fullcharge and tlp setcharge on Dell laptops.

@linrunner
Copy link
Owner

OK, then let's get started.

I'll need a bit more than just the description of the CLI because the routines in func.d/35-tlp-func-batt do a lot of checks before actually writing anything - and I don't have the hardware of course ...

I need the exact commands and their corresponding outputs / return codes for the following:

(1) Is libsmbios installed and is it supporting the new CLI?

OK, i'll guess we just have to check for smbios-battery-ctl in the PATH.

(2) Does the laptop actually support thresholds?

(3) Reading the thresholds

(4) Writing the thresholds (+ what happens with invalid param values?)

(5) Checking for batteries: are Dell laptops BAT0 only or are there models with two batteries?

For reference: I'll call the feature dellsm in TLP.

@linrunner linrunner assigned linrunner and ghost and unassigned ghost Jun 12, 2019
@userofryzen
Copy link

What happened here? I was very interested in this work as I am thinking in buying a dell device

@awehrfritz
Copy link

awehrfritz commented Jan 15, 2020

For reference: I'll call the feature dellsm in TLP.

@linrunner and @marmistrz: did you start implementing this somewhere? For instance, is there a branch that contains the initial pluming for using smbios rather than one of the kernel modules?

I have a Dell Latitude laptop that supports setting the thresholds in the bios or via the cctk utility and I would be interested in getting this to work in TLP.

@marmistrz
Copy link

marmistrz commented Jan 15, 2020

Sorry, I completely forgot about it. Unfortunately, smbios didn't have a new release after my changes accepted, so you need to patch smbios-battery-ctl manually.

OK, then let's get started.

I'll need a bit more than just the description of the CLI because the routines in func.d/35-tlp-func-batt do a lot of checks before actually writing anything - and I don't have the hardware of course ...

I need the exact commands and their corresponding outputs / return codes for the following:

(1) Is libsmbios installed and is it supporting the new CLI?
OK, i'll guess we just have to check for smbios-battery-ctl in the PATH.

You can probably grep smbios-battery-ctl --help

(2) Does the laptop actually support thresholds?

I don't know, but I guess that smbios-battery-ctl would return an error

(3) Reading the thresholds

smbios-battery-ctl --get-charging-cfg

(4) Writing the thresholds (+ what happens with invalid param values?)

smbios-battery-ctl --set-charging-mode X
smbios-battery-ctl --set-custom-charge-interval low high

I don't know what happens if params are invalid.

(5) Checking for batteries: are Dell laptops BAT0 only or are there models with two batteries?

No idea. For all those things I don't know about it's probably best to ask in dell/libsmbios (e.g. through github issues)

See also this fragment from --help.

  --get-charging-cfg    Get the current Primary Battery Charge Configuration
  --set-charging-mode=<MODE>
                        Set the current Primary Battery Charge Configuration.
                        Valid choices are: ['primarily_ac', 'adaptive',
                        'custom', 'standard', 'express']
  --set-custom-charge-interval=<START> <END>
                        Set the percentage bounds for custom charge. Both must
                        be integers. START must lie in the range [50, 95], END
                        must lie in the range [55, 100], END must be at least
                        (START + 5)

@linrunner
Copy link
Owner

I have no plans to implement this myself. Reasons are:

  1. It's hopeless without a Dell laptop at hand for try and error
  2. I've not enough time

@langemar
Copy link

langemar commented Oct 27, 2024 via email

@linrunner
Copy link
Owner

Once I set a value smbios shows the set values.

@langemar Please don't bother any further, that information is enough for me.

linrunner added a commit that referenced this issue Oct 28, 2024
    * Supports Dell laptops
    * Requires dell_laptop module as of Linux 6.12
    * Start and stop threshold
    * Force discharge not supported

    * charge_control_start_threshold:
      - Valid values: 50..95
      - Default value: 95

    * charge_control_end_threshold:
      - Valid values: 55..100
      - Default value: 100

References:
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/dell?id=ab58016c68cc5b8c3622e38b7db64994e4833d9f
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/platform/x86/dell/dell-laptop.c
* #379 (comment)
@vkhodygo

This comment was marked as off-topic.

@langemar

This comment was marked as off-topic.

@linrunner
Copy link
Owner

linrunner commented Nov 6, 2024

@vkhodygo Topic here is setting the charge thresholds for Dell laptops. This requires test results as described in #379 (comment). Your post does not contain any test results. How you broke your system is offtopic in this issue.

@linrunner
Copy link
Owner

Linux 6.12 is out.

@serycjon it's available in the Arch repos right now. So nothing is stopping you from testing :-).

@AkechiShiro What about NixOS?

@AkechiShiro
Copy link

@linrunner 6.12 is available in NixOS as well (in unstable), I'm just waiting for it to land in a new stable release (was planned the 22 November but currently delayed due to some regression in curl)

@okarin69

This comment was marked as off-topic.

@linrunner
Copy link
Owner

linrunner commented Nov 26, 2024

@okarin69 Thank you for the info, but in this issue it is offtopic and distracting.

@linrunner linrunner changed the title [Dell] Battery Care (as of Linux 6.12) Battery Care for Dell laptops Nov 26, 2024
@serycjon
Copy link

Finally a bit of time to reboot and try it - seems ok?

sudo tlp-stat -s -b -v
--- TLP 1.7.0 --------------------------------------------

+++ System Info
System         = Dell Inc.  Latitude 5491
BIOS           = 1.15.0
OS Release     = Arch Linux
Kernel         = 6.12.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 16:04:27 +0000 x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=d8c139f4-1622-47b9-8e7c-f927e363cc0a rw loglevel=3 quiet
Init system    = systemd
Boot mode      = UEFI
Suspend mode   = s2idle [deep]

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 05:13:46 PM, 1034 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: dell
Supported features: charge thresholds
Driver usage:
* natacpi (dell_laptop) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  50..95(default)
* STOP_CHARGE_THRESH_BAT0/1:   55..100(default)

+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   = SMP
/sys/class/power_supply/BAT0/model_name                     = DELL GD1JP65
/sys/class/power_supply/BAT0/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT0/charge_full_design             =   8947 [mAh]
/sys/class/power_supply/BAT0/charge_full                    =   7284 [mAh]
/sys/class/power_supply/BAT0/charge_now                     =   4415 [mAh]
/sys/class/power_supply/BAT0/current_now                    =      1 [mA]
/sys/class/power_supply/BAT0/status                         = Not charging

/sys/class/power_supply/BAT0/voltage_min_design             =   7600 [mV]
/sys/class/power_supply/BAT0/voltage_now                    =   7817 [mV]

/sys/class/power_supply/BAT0/charge_control_start_threshold =     50 [%]
/sys/class/power_supply/BAT0/charge_control_end_threshold   =     80 [%]

Charge                                                      =   60.6 [%]
Capacity                                                    =   81.4 [%]

sudo ./charge-thresholds_dell
#1      # +++ Dell laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2      #
#3      # --- tlp start
#4      sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5      sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6      sudo tlp start -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#7      sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#8      sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#9      sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#10     sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#11     sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#12     sudo tlp start -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#13     #
#14     # --- tlp setcharge w/o arguments
#15     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
#16     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100"
#17     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0"
#18     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101"
#19     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91"
#20     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#21     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#22     sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#23     sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#24     #
#25     # --- tlp setcharge w/ arguments
#26     sudo tlp setcharge 60 100 -- X_SOC_CHECK=0
#27     sudo tlp setcharge 100 100 -- X_BAT_PLUGIN_SIMULATE=dell
#28     sudo tlp setcharge 50 0 -- X_BAT_PLUGIN_SIMULATE=dell
#29     sudo tlp setcharge 50 101 -- X_BAT_PLUGIN_SIMULATE=dell
#30     sudo tlp setcharge XYZZY 0 -- X_BAT_PLUGIN_SIMULATE=dell
#31     sudo tlp setcharge 50 XYZZY -- X_BAT_PLUGIN_SIMULATE=dell
#32     sudo tlp setcharge 90 91 -- X_BAT_PLUGIN_SIMULATE=dell
#33     sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#34     sudo tlp setcharge 90 95 -- X_THRESH_SIMULATE_READERR="1"
#35     sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#36     sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=dell
#37     sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#38     sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#39     sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#40     #
#41     # --- tlp-stat
#42     sudo tlp-stat -b | grep -E 'charge_(control|behaviour)'
#43     sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_(control|behaviour)'
#44     #
#45     # --- Reset test machine to configured thresholds
#46     sudo tlp setcharge BAT0  > /dev/null 2>&1
#47     #
OK: 47 of 47 tests passed

@linrunner
Copy link
Owner

@serycjon looks perfect. Thank you for testing.

@Sempro97
Copy link

Sempro97 commented Dec 10, 2024

Hi! Thank you for the amazing work!
This is my test with dell xps 9560:

sudo tlp-stat -s -b -v
--- TLP 1.7.0 --------------------------------------------

+++ System Info
System         = Dell Inc.  XPS 15 9560
BIOS           = 1.31.0
OS Release     = Ubuntu 24.04.1 LTS
Kernel         = 6.12.4-serro #1 SMP PREEMPT_DYNAMIC Mon Dec  9 23:50:07 CET 2024 x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.12.4-serro root=UUID=57a7eaba-23b9-4dbc-9def-e8737e17fea3 ro
Init system    = systemd v255 (255.4-1ubuntu8.4)
Boot mode      = UEFI
Suspend mode   = s2idle [deep]

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 10:07:23 PM, 14 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: dell
Supported features: charge thresholds
Driver usage:
* natacpi (dell_laptop) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  50..95(default)
* STOP_CHARGE_THRESH_BAT0/1:   55..100(default)

+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   = SMP
/sys/class/power_supply/BAT0/model_name                     = DELL GPM0365
/sys/class/power_supply/BAT0/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT0/charge_full_design             =   8509 [mAh]
/sys/class/power_supply/BAT0/charge_full                    =   7340 [mAh]
/sys/class/power_supply/BAT0/charge_now                     =   5827 [mAh]
/sys/class/power_supply/BAT0/current_now                    =      1 [mA]
/sys/class/power_supply/BAT0/status                         = Not charging

/sys/class/power_supply/BAT0/voltage_min_design             =  11400 [mV]
/sys/class/power_supply/BAT0/voltage_now                    =  13015 [mV]

/sys/class/power_supply/BAT0/charge_control_start_threshold =     75 [%]
/sys/class/power_supply/BAT0/charge_control_end_threshold   =     80 [%]
/sys/class/power_supply/BAT0/charge_types                   = Trickle Fast Standard Adaptive [Custom] [%]

Charge                                                      =   79.4 [%]
Capacity                                                    =   86.3 [%]

sudo ./charge-thresholds_dell
#1	# +++ Dell laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2	#
#3	# --- tlp start
#4	sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5	sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
--------------------------------------------------------------------------------
[FAILED #5, line 14] sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1,3 @@
+Error: writing start charge threshold for BAT0 failed.
+Error: writing stop charge threshold for BAT0 failed.
 TLP started in AC mode (auto).
--------------------------------------------------------------------------------
#6	sudo tlp start -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#7	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#8	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#9	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#10	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
--------------------------------------------------------------------------------
[FAILED #10, line 28] sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1,3 @@
+Error: writing stop charge threshold for BAT0 failed.
+Error: writing start charge threshold for BAT0 failed.
 TLP started in AC mode (auto).
--------------------------------------------------------------------------------
#11	sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
--------------------------------------------------------------------------------
[FAILED #11, line 30] sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1,3 @@
+Error: writing stop charge threshold for BAT0 failed.
+Error: writing start charge threshold for BAT0 failed.
 TLP started in AC mode (auto).
--------------------------------------------------------------------------------
#12	sudo tlp start -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#13	#
#14	# --- tlp setcharge w/o arguments
#15	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
--------------------------------------------------------------------------------
[FAILED #15, line 36] sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  60
-  stop  = 100 (no change)
+  start =  60 (Error: write failed)
+  stop  = 100 (Error: write failed)
--------------------------------------------------------------------------------
#16	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100"
#17	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0"
#18	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101"
#19	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91"
#20	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
--------------------------------------------------------------------------------
[FAILED #20, line 48] sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  90
-  stop  =  95
+  stop  =  95 (Error: write failed)
+  start =  90 (Error: write failed)
--------------------------------------------------------------------------------
#21	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
--------------------------------------------------------------------------------
[FAILED #21, line 52] sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  90 (no change)
-  stop  =  95 (no change)
+  stop  =  95 (Error: write failed)
+  start =  90 (Error: write failed)
--------------------------------------------------------------------------------
#22	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
--------------------------------------------------------------------------------
[FAILED #22, line 56] sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  stop  = 100
-  start =  95
+  stop  = 100 (Error: write failed)
+  start =  95 (Error: write failed)
--------------------------------------------------------------------------------
#23	sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#24	#
#25	# --- tlp setcharge w/ arguments
#26	sudo tlp setcharge 60 100 -- X_SOC_CHECK=0
--------------------------------------------------------------------------------
[FAILED #26, line 64] sudo tlp setcharge 60 100 -- X_SOC_CHECK=0
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  60
-  stop  = 100 (no change)
+  start =  60 (Error: write failed)
+  stop  = 100 (Error: write failed)
--------------------------------------------------------------------------------
#27	sudo tlp setcharge 100 100 -- X_BAT_PLUGIN_SIMULATE=dell
#28	sudo tlp setcharge 50 0 -- X_BAT_PLUGIN_SIMULATE=dell
#29	sudo tlp setcharge 50 101 -- X_BAT_PLUGIN_SIMULATE=dell
#30	sudo tlp setcharge XYZZY 0 -- X_BAT_PLUGIN_SIMULATE=dell
#31	sudo tlp setcharge 50 XYZZY -- X_BAT_PLUGIN_SIMULATE=dell
#32	sudo tlp setcharge 90 91 -- X_BAT_PLUGIN_SIMULATE=dell
#33	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
--------------------------------------------------------------------------------
[FAILED #33, line 80] sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  90
-  stop  =  95
+  stop  =  95 (Error: write failed)
+  start =  90 (Error: write failed)
--------------------------------------------------------------------------------
#34	sudo tlp setcharge 90 95 -- X_THRESH_SIMULATE_READERR="1"
#35	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
--------------------------------------------------------------------------------
[FAILED #35, line 86] sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  start =  90 (no change)
-  stop  =  95 (no change)
+  stop  =  95 (Error: write failed)
+  start =  90 (Error: write failed)
--------------------------------------------------------------------------------
#36	sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=dell
--------------------------------------------------------------------------------
[FAILED #36, line 90] sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=dell
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT0:
-  stop  = 100
-  start =  95
+  stop  = 100 (Error: write failed)
+  start =  95 (Error: write failed)
--------------------------------------------------------------------------------
#37	sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#38	sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#39	sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#40	#
#41	# --- tlp-stat
#42	sudo tlp-stat -b | grep -E 'charge_(control|behaviour)'
--------------------------------------------------------------------------------
[FAILED #42, line 102] sudo tlp-stat -b | grep -E 'charge_(control|behaviour)'
@@ -1,2 +1,2 @@
-/sys/class/power_supply/BAT0/charge_control_start_threshold =     95 [%]
-/sys/class/power_supply/BAT0/charge_control_end_threshold   =    100 [%]
+/sys/class/power_supply/BAT0/charge_control_start_threshold =     75 [%]
+/sys/class/power_supply/BAT0/charge_control_end_threshold   =     80 [%]
--------------------------------------------------------------------------------
#43	sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_(control|behaviour)'
#44	#
#45	# --- Reset test machine to configured thresholds
#46	sudo tlp setcharge BAT0  > /dev/null 2>&1
#47	#

FAIL: 12 of 47 tests failed

grep . /sys/class/power_supply/BAT0/* 2> /dev/null | grep -v uevent
/sys/class/power_supply/BAT0/alarm:0
/sys/class/power_supply/BAT0/capacity:79
/sys/class/power_supply/BAT0/capacity_level:Normal
/sys/class/power_supply/BAT0/charge_control_end_threshold:80
/sys/class/power_supply/BAT0/charge_control_start_threshold:75
/sys/class/power_supply/BAT0/charge_full:7340000
/sys/class/power_supply/BAT0/charge_full_design:8509000
/sys/class/power_supply/BAT0/charge_now:5827000
/sys/class/power_supply/BAT0/charge_types:Trickle Fast Standard Adaptive [Custom]
/sys/class/power_supply/BAT0/current_now:1000
/sys/class/power_supply/BAT0/cycle_count:0
/sys/class/power_supply/BAT0/manufacturer:SMP
/sys/class/power_supply/BAT0/model_name:DELL GPM0365
/sys/class/power_supply/BAT0/present:1
/sys/class/power_supply/BAT0/serial_number:1566
/sys/class/power_supply/BAT0/status:Not charging
/sys/class/power_supply/BAT0/technology:Li-ion
/sys/class/power_supply/BAT0/type:Battery
/sys/class/power_supply/BAT0/voltage_min_design:11400000
/sys/class/power_supply/BAT0/voltage_now:13017000

@linrunner
Copy link
Owner

@Sempro97 looks as if the thresholds aren't writable at all. Please try manually:

echo "70" | sudo tee -a /sys/class/power_supply/BAT0/charge_control_start_threshold
echo "90" | sudo tee -a /sys/class/power_supply/BAT0/charge_control_end_threshold
sudo tlp-stat -b

@Sempro97
Copy link

Sempro97 commented Dec 11, 2024

@linrunner with this command i was able to change the thresholds:
sudo ./cctk --PrimaryBattChargeCfg=Custom:74-81 --ValSetupPwd=*******
The last argument is the password that i set on bios.
I have disabled the password in bios.
New run of test:

sudo ./unit-tests/charge-thresholds_dell
   #1	# +++ Dell laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2	#
#3	# --- tlp start
#4	sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #4, line 12] sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#5	sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #5, line 14] sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#6	sudo tlp start -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #6, line 16] sudo tlp start -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1,2 +1,2 @@
 Error in configuration at START_CHARGE_THRESH_BAT0="100": not specified, invalid or out of range (50..95). Battery skipped.
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#7	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #7, line 19] sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1,2 +1,2 @@
 Error in configuration at STOP_CHARGE_THRESH_BAT0="0": not specified, invalid or out of range (55..100). Battery skipped.
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#8	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #8, line 22] sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1,2 +1,2 @@
 Error in configuration at STOP_CHARGE_THRESH_BAT0="101": not specified, invalid or out of range (55..100). Battery skipped.
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#9	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #9, line 25] sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1,2 +1,2 @@
 Error in configuration: START_CHARGE_THRESH_BAT0 > STOP_CHARGE_THRESH_BAT0 - 5. Battery skipped.
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#10	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #10, line 28] sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#11	sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #11, line 30] sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#12	sudo tlp start -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #12, line 32] sudo tlp start -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#13	#
#14	# --- tlp setcharge w/o arguments
#15	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
#16	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100"
#17	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0"
#18	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101"
#19	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91"
#20	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#21	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#22	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#23	sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#24	#
#25	# --- tlp setcharge w/ arguments
#26	sudo tlp setcharge 60 100 -- X_SOC_CHECK=0
#27	sudo tlp setcharge 100 100 -- X_BAT_PLUGIN_SIMULATE=dell
#28	sudo tlp setcharge 50 0 -- X_BAT_PLUGIN_SIMULATE=dell
#29	sudo tlp setcharge 50 101 -- X_BAT_PLUGIN_SIMULATE=dell
#30	sudo tlp setcharge XYZZY 0 -- X_BAT_PLUGIN_SIMULATE=dell
#31	sudo tlp setcharge 50 XYZZY -- X_BAT_PLUGIN_SIMULATE=dell
#32	sudo tlp setcharge 90 91 -- X_BAT_PLUGIN_SIMULATE=dell
#33	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#34	sudo tlp setcharge 90 95 -- X_THRESH_SIMULATE_READERR="1"
#35	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#36	sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=dell
#37	sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#38	sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#39	sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#40	#
#41	# --- tlp-stat
#42	sudo tlp-stat -b | grep -E 'charge_(control|behaviour)'
#43	sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_(control|behaviour)'
#44	#
#45	# --- Reset test machine to configured thresholds
#46	sudo tlp setcharge BAT0  > /dev/null 2>&1
#47	#

FAIL: 9 of 47 tests failed
sudo tlp-stat -s -b -v
   --- TLP 1.7.0 --------------------------------------------

+++ System Info
System         = Dell Inc.  XPS 15 9560
BIOS           = 1.31.0
OS Release     = Ubuntu 24.04.1 LTS
Kernel         = 6.12.4-serro #1 SMP PREEMPT_DYNAMIC Mon Dec  9 23:50:07 CET 2024 x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.12.4-serro root=UUID=57a7eaba-23b9-4dbc-9def-e8737e17fea3 ro
Init system    = systemd v255 (255.4-1ubuntu8.4)
Boot mode      = UEFI
Suspend mode   = s2idle [deep]

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 11:01:37 PM, 62 sec(s) ago
Mode           = battery
Power source   = battery

+++ Battery Care
Plugin: dell
Supported features: charge thresholds
Driver usage:
* natacpi (dell_laptop) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  50..95(default)
* STOP_CHARGE_THRESH_BAT0/1:   55..100(default)

+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   = SMP
/sys/class/power_supply/BAT0/model_name                     = DELL GPM0365
/sys/class/power_supply/BAT0/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT0/charge_full_design             =   8509 [mAh]
/sys/class/power_supply/BAT0/charge_full                    =   7340 [mAh]
/sys/class/power_supply/BAT0/charge_now                     =   4835 [mAh]
/sys/class/power_supply/BAT0/current_now                    =    743 [mA]
/sys/class/power_supply/BAT0/status                         = Discharging

/sys/class/power_supply/BAT0/voltage_min_design             =  11400 [mV]
/sys/class/power_supply/BAT0/voltage_now                    =  12336 [mV]

/sys/class/power_supply/BAT0/charge_control_start_threshold =     95 [%]
/sys/class/power_supply/BAT0/charge_control_end_threshold   =    100 [%]
/sys/class/power_supply/BAT0/charge_types                   = Trickle Fast Standard Adaptive [Custom] [%]

Charge                                                      =   65.9 [%]
Capacity                                                    =   86.3 [%]

EDIT: I was running tests without ac plugged. With the ac plugged all test pass!

sudo ./unit-tests/charge-thresholds_dell
#1	# +++ Dell laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2	#
#3	# --- tlp start
#4	sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5	sudo tlp start -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6	sudo tlp start -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#7	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#8	sudo tlp start -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#9	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#10	sudo tlp start -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#11	sudo tlp start -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#12	sudo tlp start -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#13	#
#14	# --- tlp setcharge w/o arguments
#15	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
#16	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100"
#17	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0"
#18	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101"
#19	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91"
#20	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#21	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#22	sudo tlp setcharge -- START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#23	sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#24	#
#25	# --- tlp setcharge w/ arguments
#26	sudo tlp setcharge 60 100 -- X_SOC_CHECK=0
#27	sudo tlp setcharge 100 100 -- X_BAT_PLUGIN_SIMULATE=dell
#28	sudo tlp setcharge 50 0 -- X_BAT_PLUGIN_SIMULATE=dell
#29	sudo tlp setcharge 50 101 -- X_BAT_PLUGIN_SIMULATE=dell
#30	sudo tlp setcharge XYZZY 0 -- X_BAT_PLUGIN_SIMULATE=dell
#31	sudo tlp setcharge 50 XYZZY -- X_BAT_PLUGIN_SIMULATE=dell
#32	sudo tlp setcharge 90 91 -- X_BAT_PLUGIN_SIMULATE=dell
#33	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#34	sudo tlp setcharge 90 95 -- X_THRESH_SIMULATE_READERR="1"
#35	sudo tlp setcharge 90 95 -- X_BAT_PLUGIN_SIMULATE=dell
#36	sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=dell
#37	sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#38	sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#39	sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=dell
#40	#
#41	# --- tlp-stat
#42	sudo tlp-stat -b | grep -E 'charge_(control|behaviour)'
#43	sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_(control|behaviour)'
#44	#
#45	# --- Reset test machine to configured thresholds
#46	sudo tlp setcharge BAT0  > /dev/null 2>&1
#47	#
OK: 47 of 47 tests passed

@linrunner
Copy link
Owner

linrunner commented Dec 13, 2024

@Sempro97

sudo ./cctk --PrimaryBattChargeCfg=Custom:74-81 --ValSetupPwd=*******

This is of little help here because the cctk tool from Dell writes the charge thresholds in a different, proprietery way. I would have been interested in the echo commands above. But that doesn't matter now that you have found the solution:

EDIT: I was running tests without ac plugged. With the ac plugged all test pass!
Great.

//--- Nonsense deleted
This is the first laptop brand to make AC a condition for setting the charge thresholds via Sysfs. But it doesn't seem to occur with cctk.

It would be helpful if you open a kernel bug or email the kernel developer directly -> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/dell?id=ab58016c68cc5b8c3622e38b7db64994e4833d9f

In the meantime, I'll consider whether I should add a check for AC. But this only makes sense if someone calls tlp setcharge in the terminal, not in the background tasks of TLP, e.g. at system startup.
---//

@linrunner linrunner changed the title Battery Care for Dell laptops Battery Care for Dell laptops (Kernel 6.12 required) Jan 11, 2025
@linrunner
Copy link
Owner

TLP 1.8.0 Beta 1 has been released. Please test again if it works for you -> #781

@linrunner
Copy link
Owner

@Sempro97 @serycjon @langemar Analysis of the write error continues in #785.

@langemar
Copy link

langemar commented Jan 26, 2025

This is probably in the wrong issue now, but I'm not sure which should be used...
I've tested again using Fedora Workstation Live Rawhide Image from 26.01.2025 and TLP-1.8.0-beta.1 Tarball.

My charge type was always set to custom using smbios, which I use until TLP is ready and available in Fedora Stable.
$ sudo smbios-battery-ctl --set-custom-charge-interval 50 80 Custom charge interval has been set to (50, 80)

# uname -a

Linux localhost-live 6.13.0-0.rc7.20250114gitc45323b7560e.56.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jan 14 16:33:15 UTC 2025 x86_64 GNU/Linux

TLP/unit-tests# ./test-bc_cros-ec-v2.sh
        # bata=BAT0 batb=BAT2 xinc=
#1	# +++ ChromeOS EC (cmd v2) laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2	#
#3	# --- tlp start
#4	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata} STOP_CHARGE_THRESH_${bata} START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}=
#5	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="60" STOP_CHARGE_THRESH_${bata}="100" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}=
#6	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="0" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}= 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #6, line 20] sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="0" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}= 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,2 @@
-Error in configuration at STOP_CHARGE_THRESH_BATA="0": not specified, invalid or out of range (1..100). Battery skipped.
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Battery skipped.
 TLP started in AC mode (auto).
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#7	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="0" STOP_CHARGE_THRESH_${bata}="101" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}= 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #7, line 23] sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="0" STOP_CHARGE_THRESH_${bata}="101" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}= 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,2 @@
-Error in configuration at STOP_CHARGE_THRESH_BATA="101": not specified, invalid or out of range (1..100). Battery skipped.
+Error in configuration at START_CHARGE_THRESH_BATA="0": not specified, invalid or out of range (50..95). Battery skipped.
 TLP started in AC mode (auto).
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#8	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="86" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}=
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #8, line 26] sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="86" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}=
@@ -1 +1,2 @@
+Error in configuration at START_CHARGE_THRESH_BAT0="na": not specified, invalid or out of range (50..95). Battery skipped.
 TLP started in AC mode (auto).
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#9	sudo tlp start -- ${xinc} START_CHARGE_THRESH_${bata}="DEF" STOP_CHARGE_THRESH_${bata}="DEF" START_CHARGE_THRESH_${batb}= STOP_CHARGE_THRESH_${batb}=
#10	sudo tlp start -- ${xinc} NATACPI_ENABLE=0 START_CHARGE_THRESH_${bata}="DEF" STOP_CHARGE_THRESH_${bata}="DEF"
#11	#
#12	# --- tlp setcharge w/o arguments
#13	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="60" STOP_CHARGE_THRESH_${bata}="100" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #13, line 34] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="60" STOP_CHARGE_THRESH_${bata}="100" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,3 @@
-Setting temporary charge threshold(s) for battery BATA:
+Setting temporary charge thresholds for battery BATA:
+  start =  60
   stop  = 100 (no change)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#14	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="0" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #14, line 37] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="0" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BATA="0": not specified, invalid or out of range (1..100). Aborted.
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#15	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="0" STOP_CHARGE_THRESH_${bata}="101" 2>&1| sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #15, line 39] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="0" STOP_CHARGE_THRESH_${bata}="101" 2>&1| sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BATA="101": not specified, invalid or out of range (1..100). Aborted.
+Error in configuration at START_CHARGE_THRESH_BATA="0": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#16	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="ABCDE" STOP_CHARGE_THRESH_${bata}="XYZZY" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #16, line 41] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="ABCDE" STOP_CHARGE_THRESH_${bata}="XYZZY" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BATA="XYZZY": not specified, invalid or out of range (1..100). Aborted.
+Error in configuration at START_CHARGE_THRESH_BATA="ABCDE": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#17	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="100" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #17, line 43] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="100" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  = 100 (no change)
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#18	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="86" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #18, line 46] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="86" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  86
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#19	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="80" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #19, line 49] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="80" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  80
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#20	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="80" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #20, line 52] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="na" STOP_CHARGE_THRESH_${bata}="80" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  80 (no change)
+Error in configuration at START_CHARGE_THRESH_BATA="na": not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#21	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="DEF" STOP_CHARGE_THRESH_${bata}="DEF" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #21, line 55] sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_${bata}="DEF" STOP_CHARGE_THRESH_${bata}="DEF" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,3 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  = 100
+Setting temporary charge thresholds for battery BATA:
+  start =  95
+  stop  = 100 (no change)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#22	sudo tlp setcharge -- ${xinc} NATACPI_ENABLE=0 START_CHARGE_THRESH_${bata}="DEF" STOP_CHARGE_THRESH_${bata}="DEF" 2>&1 | sed -r "s/${bata}/BATA/"
#23	#
#24	# --- tlp setcharge w/ arguments
#25	sudo tlp setcharge 60 100 ${bata} -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #25, line 62] sudo tlp setcharge 60 100 ${bata} -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,3 @@
-Setting temporary charge threshold(s) for battery BATA:
+Setting temporary charge thresholds for battery BATA:
+  start =  60
   stop  = 100 (no change)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#26	sudo tlp setcharge 0 0 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #26, line 65] sudo tlp setcharge 0 0 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error: stop charge threshold (0) for BATA is not specified, invalid or out of range (1..100). Aborted.
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#27	sudo tlp setcharge 0 101 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #27, line 67] sudo tlp setcharge 0 101 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error: stop charge threshold (101) for BATA is not specified, invalid or out of range (1..100). Aborted.
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#28	sudo tlp setcharge ABCDE 0 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #28, line 69] sudo tlp setcharge ABCDE 0 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error: stop charge threshold (0) for BATA is not specified, invalid or out of range (1..100). Aborted.
+Error: start charge threshold (ABCDE) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#29	sudo tlp setcharge 0 XYZZY -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #29, line 71] sudo tlp setcharge 0 XYZZY -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1 +1 @@
-Error: stop charge threshold (XYZZY) for BATA is not specified, invalid or out of range (1..100). Aborted.
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#30	sudo tlp setcharge 97 100 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #30, line 73] sudo tlp setcharge 97 100 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  = 100 (no change)
+Error: start charge threshold (97) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#31	sudo tlp setcharge 0 66 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #31, line 76] sudo tlp setcharge 0 66 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  66
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#32	sudo tlp setcharge 0 60 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #32, line 79] sudo tlp setcharge 0 60 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  60
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#33	sudo tlp setcharge 0 60 -- ${xinc} X_THRESH_SIMULATE_STOP="100" 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #33, line 82] sudo tlp setcharge 0 60 -- ${xinc} X_THRESH_SIMULATE_STOP="100" 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  60
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#34	sudo tlp setcharge 0 60 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #34, line 85] sudo tlp setcharge 0 60 -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  =  60 (no change)
+Error: start charge threshold (0) for battery BATA is not specified, invalid or out of range (50..95). Aborted.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#35	sudo tlp setcharge DEF DEF -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
-------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #35, line 88] sudo tlp setcharge DEF DEF -- ${xinc} 2>&1 | sed -r "s/${bata}/BATA/"
@@ -1,2 +1,3 @@
-Setting temporary charge threshold(s) for battery BATA:
-  stop  = 100
+Setting temporary charge thresholds for battery BATA:
+  start =  95
+  stop  = 100 (no change)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
#36	sudo tlp setcharge ${batb} -- ${xinc} 2>&1 | sed -r "s/${batb}/BATB/"
#37	sudo tlp setcharge 0 3 ${batb} -- ${xinc} 2>&1 | sed -r "s/${batb}/BATB/"
#38	sudo tlp setcharge XYZZY ABCDE ${batb} -- ${xinc} 2>&1 | sed -r "s/${batb}/BATB/"
#39	#
#40	# --- tlp-stat
#41	sudo tlp-stat -b -- ${xinc} | grep "${bata}/charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
#42	sudo tlp-stat -b -- ${xinc} X_THRESH_SIMULATE_READERR=1 | grep "${bata}/charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
#43	#
#44	# --- Reset test machine to configured thresholds
#45	sudo tlp setcharge ${bata} -- ${xinc} > /dev/null 2>&1
#46	#
 
FAIL: 23 of 46 tests failed
 
+++ Test Summary ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
charge-thresholds_cros-ec-v2                       --> FAIL: 23 of 46 tests failed
Despite failing, my charge limits where changed after this test.
# tlp-stat -s -b -v
--- TLP 1.8.0-beta.1 --------------------------------------------
 
+++ System Info
System         = Dell Inc.  Latitude 3450
BIOS           = 1.8.0
EC Firmware    = 1.5
OS Release     = Fedora Linux 42 (Workstation Edition Prerelease)
Kernel         = 6.13.0-0.rc7.20250114gitc45323b7560e.56.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jan 14 16:33:15 UTC 2025 x86_64
/proc/cmdline  = BOOT_IMAGE=/images/pxeboot/vmlinuz root=live:CDLABEL=Fedora-WS-Live-rawh-20250126-n-0 rd.live.image quiet rhgb
Init system    = systemd 
Boot mode      = UEFI
Suspend mode   = [s2idle]
SELinux status = enabled (enforcing)
 
+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 09:07:56 AM, 52 sec(s) ago
Mode           = AC
Power source   = AC
 
+++ Battery Care
Plugin: dell
Supported features: charge thresholds
Driver usage:
* natacpi (dell_laptop) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  50..95(default)
* STOP_CHARGE_THRESH_BAT0/1:   55..100(default)
 
+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   = BYD
/sys/class/power_supply/BAT0/model_name                     = DELL 7RDGP45O
/sys/class/power_supply/BAT0/cycle_count                    =      5
/sys/class/power_supply/BAT0/charge_full_design             =   3685 [mAh]
/sys/class/power_supply/BAT0/charge_full                    =   3685 [mAh]
/sys/class/power_supply/BAT0/charge_now                     =   2954 [mAh]
/sys/class/power_supply/BAT0/current_now                    =   1873 [mA]
/sys/class/power_supply/BAT0/status                         = Charging
 
/sys/class/power_supply/BAT0/voltage_min_design             =  11400 [mV]
/sys/class/power_supply/BAT0/voltage_now                    =  12504 [mV]
 
/sys/class/power_supply/BAT0/charge_control_start_threshold =     95 [%]
/sys/class/power_supply/BAT0/charge_control_end_threshold   =    100 [%]
/sys/class/power_supply/BAT0/charge_types                   = Trickle Fast Standard Adaptive [Custom]
 
Charge                                                      =   80.2 [%]
Capacity                                                    =  100.0 [%]
# grep . /sys/class/power_supply/BAT0/* 2> /dev/null | grep -v ueven
/sys/class/power_supply/BAT0/alarm:368000
/sys/class/power_supply/BAT0/capacity:81
/sys/class/power_supply/BAT0/capacity_level:Normal
/sys/class/power_supply/BAT0/charge_control_end_threshold:100
/sys/class/power_supply/BAT0/charge_control_start_threshold:95
/sys/class/power_supply/BAT0/charge_full:3685000
/sys/class/power_supply/BAT0/charge_full_design:3685000
/sys/class/power_supply/BAT0/charge_now:2995000
/sys/class/power_supply/BAT0/charge_types:Trickle Fast Standard Adaptive [Custom]
/sys/class/power_supply/BAT0/current_now:1873000
/sys/class/power_supply/BAT0/cycle_count:5
/sys/class/power_supply/BAT0/eppid:CN07RDGPBDS0045O50COA02
/sys/class/power_supply/BAT0/manufacturer:BYD
/sys/class/power_supply/BAT0/model_name:DELL 7RDGP45O
/sys/class/power_supply/BAT0/present:1
/sys/class/power_supply/BAT0/serial_number:419
/sys/class/power_supply/BAT0/status:Charging
/sys/class/power_supply/BAT0/technology:Li-poly
/sys/class/power_supply/BAT0/temp:196
/sys/class/power_supply/BAT0/type:Battery
/sys/class/power_supply/BAT0/voltage_min_design:11400000
/sys/class/power_supply/BAT0/voltage_now:12559000
TLP/unit-tests# ./charge-thresholds_dell
#1	# +++ Dell laptops +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2	#
#3	# --- tlp start
#4	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#7	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#8	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#9	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#10	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#11	sudo tlp start -- ${xinc} START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#12	sudo tlp start -- ${xinc} NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#13	#
#14	# --- tlp setcharge w/o arguments
#15	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="60" STOP_CHARGE_THRESH_BAT0="100" X_SOC_CHECK=0
#16	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="100" STOP_CHARGE_THRESH_BAT0="100"
#17	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="0"
#18	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="50" STOP_CHARGE_THRESH_BAT0="101"
#19	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="91"
#20	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#21	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="90" STOP_CHARGE_THRESH_BAT0="95"
#22	sudo tlp setcharge -- ${xinc} START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#23	sudo tlp setcharge -- ${xinc} NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT0="DEF" STOP_CHARGE_THRESH_BAT0="DEF"
#24	#
#25	# --- tlp setcharge w/ arguments
#26	sudo tlp setcharge 60 100 -- ${xinc} X_SOC_CHECK=0
#27	sudo tlp setcharge 100 100 -- ${xinc}
#28	sudo tlp setcharge 50 0 -- ${xinc}
#29	sudo tlp setcharge 50 101 -- ${xinc}
#30	sudo tlp setcharge XYZZY 0 -- ${xinc}
#31	sudo tlp setcharge 50 XYZZY -- ${xinc}
#32	sudo tlp setcharge 90 91 -- ${xinc}
#33	sudo tlp setcharge 90 95 -- ${xinc}
#34	sudo tlp setcharge 90 95 -- ${xinc} X_THRESH_SIMULATE_READERR="1"
#35	sudo tlp setcharge 90 95 -- ${xinc} X_THRESH_SIMULATE_START="60" X_THRESH_SIMULATE_STOP="100"
#36	sudo tlp setcharge 90 95 -- ${xinc}
#37	sudo tlp setcharge DEF DEF -- ${xinc}
#38	sudo tlp setcharge BAT2 -- ${xinc}
#39	sudo tlp setcharge 0 3 BAT2 -- ${xinc}
#40	sudo tlp setcharge XYZZY ABCDE BAT2 -- ${xinc}
#41	#
#42	# --- tlp-stat
#43	sudo tlp-stat -b -- ${xinc} | grep -E 'BAT0/charge_(control|behaviour)'
#44	sudo tlp-stat -b -- ${xinc} X_THRESH_SIMULATE_READERR=1 | grep -E 'BAT0/charge_(control|behaviour)'
#45	#
#46	# --- Reset test machine to configured thresholds
#47	sudo tlp setcharge BAT0 - ${xinc} > /dev/null 2>&1
#48	#
OK: 48 of 48 tests passed

@linrunner
Copy link
Owner

linrunner commented Jan 26, 2025

@langemar

This is probably in the wrong issue now, but I'm not sure which should be used...

No problem :-)

I've tested again using Fedora Workstation Live Rawhide Image from 26.01.2025 and TLP-1.8.0-beta.1 Tarball.

Waving the fencepost: there's a beta repo.

My charge type was always set to custom using smbios
$ sudo smbios-battery-ctl --set-custom-charge-interval 50 80
Custom charge interval has been set to (50, 80)

Good to know as an alternative to cctk but from regular distribution repositories. 👍

which I use until TLP is ready and available in Fedora Stable.

Fedora is still stuck at 1.6.1, I don't know why the maintainer stopped working on it.

TLP/unit-tests# ./test-bc_cros-ec-v2.sh
Despite failing, my charge limits where changed after this test.
# tlp-stat -s -b -v

Wrong test. test-bc_cros-ec-v2.sh is for testing on Chromebooks and Frameworks only. Since these laptops also use charge_control_*_threshold, it partially works on Dell too.

TLP/unit-tests# ./charge-thresholds_dell

Perfect. Thank you very much for testing.

@langemar
Copy link

Thank for the pointing me to the beta repo, I was not aware that :)

Once a stable release is made I will contact the tlp maintainers and ask for the update. I assume TLP 'just works' for most people so no upgrade might be necessary. With the option to control charge on Dell I hope I can provide a reason to upgrade the package soon :)

@linrunner
Copy link
Owner

I have just released TLP 1.8.0. Thanks for your contributions. Have fun!

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

No branches or pull requests