blog.g3rt.nl
  • Home
  • About
  • Categories
  • Tags
  • Archives

Thinkpad SMAPI driver: Battery control and more

Contents

  • SMAPI driver: battery control and more
  • Battery control
  • Setting the start and stop thresholds
  • See also

SMAPI driver: battery control and more¶

In recent Debian and Ubuntu releases there's an interesting package for ThinkPad owners: tp-smapi-dkms.

By installing this package you'll get a way of controlling the battery charge stop/start thresholds, HDAPS driver and more.

Battery control¶

See the contents of the directory /sys/devices/platform/smapi/BAT0.

Setting the start and stop thresholds¶

I created a script to set those thresholds. It just sets the values in the files in /sys/devices/platform/smapi/BAT0/ and logs the actions to the logger daemon using the syslog.

Below is the script, a sensible location for it would be /usr/local/bin/set_charge_tresholds.sh:

#!/bin/bash
#Configure the three options below yourself. Only one battery is supported at the moment.
BAT=BAT0
START_TRESH=85
STOP_TRESH=90

SMAPI_LOADED=`awk '{ print $1 }' /proc/modules | grep tp_smapi | wc -l`
SMAPI_DIR=/sys/devices/platform/smapi
BAT_DIR=$SMAPI_DIR/$BAT
LOGGER=/usr/bin/logger

if [ "$SMAPI_LOADED" -gt "0" ]
then
        if [ -e $BAT_DIR/start_charge_thresh ] && [ -e $BAT_DIR/stop_charge_thresh ]
        then
                BEFORE_START=`cat $BAT_DIR/start_charge_thresh`
                BEFORE_STOP=`cat $BAT_DIR/stop_charge_thresh`
                $LOGGER -s -p syslog.info "About to change the start/stop charging tresholds for Thinkpad battery $BAT. Values before change: start=$BEFORE_START, stop=$BEFORE_STOP"
                echo $START_TRESH > $BAT_DIR/start_charge_thresh
                echo $STOP_TRESH > $BAT_DIR/stop_charge_thresh
                $LOGGER -s -p syslog.info "Successfully set start/stop charging tresholds for Thinkpad battery $BAT to start=$START_TRESH and stop=$STOP_TRESH."
        else
                $LOGGER -s -p syslog.err "Unable to set start/stop charging tresholds for Thinkpad battery $BAT; file not found."
        fi
else
        $LOGGER -s -p syslog.err "Thinkpad SMAPI kernel module seems not loaded, skipping."
fi

To call it at boot time, just add one line in your /etc/rc.local file (above the exit 0 line!):

/usr/local/bin/set_charge_tresholds.sh

See also¶

  • ThinkPad ACPI driver: fan control.
Comments
comments powered by Disqus

Related Posts

  • How to use the Thinkpad ACPI kernel module
  • How to use Thinkfan to control your Thinkpad's fan speed
  • Patch for overheating ThinkPads

Published

Jul 18, 2011

Last Updated

Jul 22, 2011

Category

Miscellaneous

Tags

  • kernel 3
  • power 3
  • ThinkPad 4

Follow me on...

  • Powered by Pelican. Theme: Elegant by Talha Mansoor