Thursday, September 6, 2012

Make new ThinkPad's charge thresholds work in Debian/Ubuntu

Instead of Intro

ThinkPad`s have been always famous for the amazing hardware compatibility with Linux. But seems this time has gone and owners of new ThinkPad`s like ThinkPad X230, T430 and of some other may have started experiencing some uncomfortable changes. The one of the such changes is inability to use tp_smapi module to set battery thresholds.

Battery charge threshold might be important for you if you want extend the battery's health. They are used to keep batteries partially charged.

I am as an owner of brand new ThinkPad x230 run into the impossibility to load tp_smapi module for my primary Debian (Testing) GNU/Linux as well as to set above mentioned thresholds. Here will be a safe workaround to fix the regression. It must work as well for Ubuntu Linux.

For the previous versions of ThinkPad`s it was simply enough to put desired integers to /sys/devices/platform/smapi/BAT{0,1}/{start,stop}_charge_thresh files to make these thresholds work. Currently there are no such special files anymore; since tp_acpi loading is failed. At least for the newest ThinkPad`s. Fortunately there is an alternative way: to set these values directly through the kernel's ACPI subsystem not ThinkPad brand controller's interface.

There is a module called acpi_call which was originally designed for easy switching video adapters in dual graphics environments. It provides a convenient interface for sending any command to ACPI subsystem; literally "call ACPI for some request". But which command to send to request a change of charge thresholds? Actually it does not matter because you should not do it by yourself. There is a special tool called tpacpi-bat (the part of tpbattstat-applet) which will do it for you.

Solution: all steps together

The only things we need to make ThinkPad`s charge thresholds work in Debian/Ubuntu are:
  1. Install acpi_call module;
  2. Install tpacpi_bat script;
  3. Configure thresholds setting on system boot-up;

acpi_call for Debian/Ubuntu

acpi_call is not included to standard Debian/Ubuntu repositories. The only way is to build it by yourself. Since I am a bit lazy about keeping in mind that with each kernel update I should rebuild acpi_call module I decided to write a simple script which will register and install it as a DKMS module.

The script could be retrieved from my git repository. The only requirement for running it is a root permission. If some packages required to build are missing you will be notified. Run it with 'run' argument and the script will do the following for you:
  • Retrieve acpi_call sources from the main git repository;
  • Register it as a DKMS module;
  • Install acpi_module to your Debian/Ubuntu system.


tpacpi_bat is also not included to standard Debian/Ubuntu repositories. It could be grabbed from the author's git repository. The script depends on Perl only and could be put anywhere on the system, e.g. to /usr/local/bin.

Thresholds on boot-up

To make charge thresholds set on system boot-up:
  • acpi_call entry must be added to /etc/modules
  • The following commands must be added to /etc/rc.local:
/usr/local/tpacpi-bat -v startChargeThreshold 0 N
/usr/local/tpacpi-bat -v stopChargeThreshold 0 K

where N and K are integers in percent of full battery capacity.

Enjoy! Thanks to this ThinkPad's batteries might be a bit healthy :).


  1. Your post is very encouraging, as I too own a ThinkPad X230. After about 6 months of use with Linux Mint Maya, the battery had deteriorated to about 44% capacity. Lenovo replaced it under warranty. I don't want this to happen again. Unfortunately, although I am somewhat technically saavy (in fact, I used to work for IBM, writing installers back in the day!) I don't know how to use git and I suspect that I am not alone. Would it be a great deal of trouble to package your solution in a ppa repo so that it can be installed with apt-get? I will try to figure out git (can't be that hard...) but I am quite sure that many others would benefit from your script if it could simply be "apt-gotten".
    Cheers, and thanks!

  2. This is useful, thanks. It appears to work on an X1 Carbon, another recent Thinkpad that doesn't like tp_smapi.

    tpacpi-bat has moved: look for it now at . Also, the script parameters' names are different, so the additions to /etc/rc.local should be updated.

    Consider this post another vote for a .deb package that does all the heavy lifting automatically ;-)

  3. What would you make the start and stop thresholds?

  4. It should be user adjustable. I set it to 80/85% in Windows, and the setting persists so long as the power remains connected during reboot.

  5. Thanks a lot for this article and the installation script.

    A newer version of the acpi_call module, notably compatible with 3.10 kernel, is available here :

    Hope this helps.

  6. Hey, does it work with ideapad?