IBM/Lenovo Thinkpad tp_smapi patch for Debian and Ubuntu systems

Friday, March 21st, 2008 at 2:24 pm | 5,138 views | trackback url
Tags: , , , , ,

ThinkPad laptops include a proprietary interface called SMAPI BIOS (System Management Application Program Interface) which provides some hardware control functionality that is not accessible by other means.

This driver exposes some features of the SMAPI BIOS through a sysfs interface. It is suitable for newer models, on which SMAPI is invoked through IO port writes. Older models use a different SMAPI interface using “thinkpad” module from the “tpctl” package.

Unfortunately, out of the box it does not build on Ubuntu or Debian systems, because of the way those Linux distributions structure their kernel source and headers in /lib/modules/…/ and /usr/src/…/

It is a simple one-line patch to fix the tp_smapi Makefile to get these package to build on stock Ubuntu/Debian systems:

--- Makefile.orig       2008-03-21 14:07:34.604072067 -0400
+++ Makefile    2008-03-21 14:13:07.669091731 -0400
@@ -3,7 +3,7 @@
 X:=$(shell false)
 KVER        := $(shell uname -r)
 KBASE       := /lib/modules/$(KVER)
-KSRC        := $(KBASE)/source
+KSRC        := /usr/src/linux-headers-$(KVER)/
 KBUILD      := $(KBASE)/build
 MOD_DIR     := $(KBASE)/kernel
 PWD         := $(shell pwd)

Basically you need to tell the KSRC variable that the kernel source is in /usr/src/linux-headers-1.2.3-foo/ and not in /lib/modules/1.2.3-foo/source/.

If you want to build tp_smapi with HDAPS support (and you probably do, if you’re on a laptop), then you’d build it as follows:

make load HDAPS=1
make install HDAPS=1

Depending on your particular configuration, you can then put tp_smapi and hdaps in your /etc/modules file to load at boot-time.

I personally use tp_smapi to set the charging and discharging thresholds of my Thinkpad batteries (3 separate Thinkpads at this point; T61p, T42p and X61s).

$ sudo echo 30 > /sys/bus/platform/drivers/smapi/smapi/BAT0/start_charge_thresh
$ sudo echo 90 > /sys/bus/platform/drivers/smapi/smapi/BAT0/stop_charge_thresh

The values above tell tp_smapi to begin charging the battery when it reaches BELOW 30% of its total capacity, and to stop charging the battery when it reaches ABOVE 90% of its total capacity.

There’s a lot of other things to play with in here, and here is a table showing some of those options, courtesy of ThinkWiki.

Here’s what my battery details are on the T61p as I type this:

$ cat /proc/acpi/battery/BAT0/info 
present:                 yes
design capacity:         84240 mWh
last full capacity:      86790 mWh
battery technology:      rechargeable
design voltage:          10800 mV
design capacity warning: 4339 mWh
design capacity low:     200 mWh
capacity granularity 1:  1 mWh
capacity granularity 2:  1 mWh
model number:            42T4511
serial number:           21169
battery type:            LION
OEM info:                SANYO

Last Modified: Wednesday, April 6th, 2011 @ 13:27

2 Responses to “IBM/Lenovo Thinkpad tp_smapi patch for Debian and Ubuntu systems”

  1. Exactly what I’ve been looking for.

    Many Thanks.

  2. Very nice!…

    Wow you are very very talented!! keep up the awesome work. You are very talented & I only wish I could write as good as you do :)…


Leave a Reply

You must be logged in to post a comment.

Bad Behavior has blocked 2450 access attempts in the last 7 days.