How to set battery charging thresholds on laptop...

Hi,

T430 here.

What works for me to set charge start threshold to 80% and stop charge threshold to 95% :

Get battery acpi handle :

sysctl dev.acpi_ibm.0.%location
dev.acpi_ibm.0.%location: handle=\_SB_.PCI0.LPC_.EC__.HKEY

Use it to set the start charge threshold :
acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCCS' -i 80

and set the stop charge threshold :
acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCSS' -i 95

Quite close to what was described in the Reddit post.
Don't know if it works on a T480.
Good luck.
what if we have dual battery thinkpad ?
 
I hope you find this script useful
if you want to collaborate and do a pull request please github
Code:
#!/bin/sh

if [ $# != 2 ]
then
  echo "No start and stop thresholds specified."
  echo "example: $ battery_ctrl.sh 70 80"
  exit
fi

ACPI_BATTERY_HANDLE=$(sysctl dev.acpi_ibm.0.%location | cut -f2 -d'=')

acpi_call -p $ACPI_BATTERY_HANDLE.BCCS -i $1

acpi_call -p $ACPI_BATTERY_HANDLE.BCSS -i $2







# Copyright (C) 2023 Dr.Amr Osman, consultant of cardiology
# License-Identifier: BSD-3-Clause
 
I hope you find this script useful
if you want to collaborate and do a pull request please github
Code:
#!/bin/sh

if [ $# != 2 ]
then
  echo "No start and stop thresholds specified."
  echo "example: $ battery_ctrl.sh 70 80"
  exit
fi

ACPI_BATTERY_HANDLE=$(sysctl dev.acpi_ibm.0.%location | cut -f2 -d'=')

acpi_call -p $ACPI_BATTERY_HANDLE.BCCS -i $1

acpi_call -p $ACPI_BATTERY_HANDLE.BCSS -i $2







# Copyright (C) 2023 Dr.Amr Osman, consultant of cardiology
# License-Identifier: BSD-3-Clause

Please see Bug 234403
 
https://github.com/dr3mro/battery_ctrl

I would be honored if you recheck it now.

That's much improved to my taste. After a thorough read I gave it a go on my T430s, after noticing that previous settings in Lenovo's windows utility were not still set, in that the 'high' State in acpiconf -i0 was 100%. (I recall having removed the battery at some time).

I immediately wished you had incorporated the code to show the existing threshold settings, perhaps with the first and only parameter being 'show'?

So I started with
Code:
root@t430s:~ # battery-ctrl.sh 89 100
start threshold was set to : 89
failed to set stop threshold.
root@t430s:~ # battery-ctrl.sh 89 99
start threshold was set to : 89
stop threshold was set to : 99
root@t430s:~ #

Which confirms that 100 is not a valid stop value, despite it being the initial unmodified value!

Apart from requesting a 'show' function, I suggest checking the acpi_ibm oid before checking and possibly loading the acpi_call module, in case non ibm|lenovo users run it, and also perhaps posting your code directly to the PR?

It may also make sense to choose a minimum practical value for start, and a minimum range between start and stop?

cheers, Ian

PS I still think committing Kevin Zheng's patch to be the best fix for this, but meanwhile a working utility is very handy. Maybe more people with other model Lenovos will test it?
 
I am just an amateur not a real developer and I really appreciate your feedback
I did try to get the current reading but I couldn't find the correct ACPI path
Also I don't think I would be able to support any other laptop except my Thinkpad as I don't have any other one to do tests on

I would find it very genetfrom you if you could help me find a proper ACPI path for current threshold,
Thanks 🙏
Amr
 
Hi there, I'm the author of the kernel patch (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234403).

If you're interested in building the kernel patch yourself:
  1. Check out the kernel sources for your system (either via Git, or download a tarball, or have already installed at /usr/src)
  2. Apply the attached patch
  3. Run cd /usr/src/sys/modules/acpi/acpi_ibm/ && make
  4. The built kernel module is located at /usr/src/amd64.amd64/sys/modules/acpi/acpi_ibm/acpi_ibm.ko
  5. You can load this directly with a full patch argument to kldload(), e.g. kldload /usr/src/amd64.amd64/sys/modules/acpi/acpi_ibm/acpi_ibm.ko. Not using an absolute or relative path will load the system version which isn't the version you want to load.
To answer dr3mro 's question, the ACPI methods for getting the threshold are different from the ACPI methods for setting the threshold. To summarize:

Sysctl NameACPI Get MethodACPI Set Method
bat0_charge_startBCTGBCCS
bat0_charge_stopBCSGBCSS
 
Yes, I've just checked, and the "%location" I get from dev.acpi_ibm... and dev.acpi_acad... is the same.
So the acpi_call commands above are supposed to work.

As far as I know, it's not a common feature on laptops, even if exists for ages on Thinkpads. I *think* some Dell and Sony computers implement it, of course probably in a different way.
So it's not something all laptops expose, right? I remember looking at my Toshiba's battery, and from what I gathered the ACPI does not expose battery related stuff at all.

Is there a way to check if any battery controls are available to modify?
 
So it's not something all laptops expose, right? I remember looking at my Toshiba's battery, and from what I gathered the ACPI does not expose battery related stuff at all.

Is there a way to check if any battery controls are available to modify?

Yes, these particular ACPI methods are only exposed by older ThinkPad laptops.

Unfortunately there's not usually a good way to check. If these features are implemented at all, they are probably accessible through system-dependent interfaces like ACPI or I2C. I would suggest booting an OEM Windows to see if this is a feature that is possible at all in the first place, and only once you've confirmed that this is available for your system, to investigate how to make it available from FreeBSD.
 
Hi there, I'm the author of the kernel patch (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234403).

If you're interested in building the kernel patch yourself:
  1. Check out the kernel sources for your system (either via Git, or download a tarball, or have already installed at /usr/src)
  2. Apply the attached patch
  3. Run cd /usr/src/sys/modules/acpi/acpi_ibm/ && make
  4. The built kernel module is located at /usr/src/amd64.amd64/sys/modules/acpi/acpi_ibm/acpi_ibm.ko
  5. You can load this directly with a full patch argument to kldload(), e.g. kldload /usr/src/amd64.amd64/sys/modules/acpi/acpi_ibm/acpi_ibm.ko. Not using an absolute or relative path will load the system version which isn't the version you want to load.
To answer dr3mro 's question, the ACPI methods for getting the threshold are different from the ACPI methods for setting the threshold. To summarize:

Sysctl NameACPI Get MethodACPI Set Method
bat0_charge_startBCTGBCCS
bat0_charge_stopBCSGBCSS
not working on thinkpad X270 for me
no sysctl were added
 
Back
Top