Wednesday 18 January 2012

Arch Linux on Thinkpad Edge 11

I use Arch Linux on my Thinkpad Edge 11 notebook (Intel version with Core i3 Duo (i3-380UM)). This is my office device and I spend my everyday life using this tiny little computer. I briefly concluded the first steps and some minor issues during installation here. Now I am collecting all the device-specific settings I made for fine-tuning Arch Linux for this laptop model.

TP smapi
This feature set provides Thinkpad users with detailed battery charge/discharge control, battery status information and hard disk protection.
The package is called tp_smapi and can be installed from AUR. After installation add tp_smapi to your MODULES array of your /etc/rc.conf.
Details can be found in the tp_smapi page of the Arch Wiki.

After installation and loading the tp_smapi module several useful information can be read out and set up from the /sys/devices/platform/smapi/ directory.

The default battery is BAT0, its details can be read from the files under
/sys/devices/platform/smapi/BAT0/

I show some examples how this service can be used:

Battery indicator
I use simple tiling window managers (like awesome and wmfs) and I created a statusbar script to show (among others) the actual battery percentage and status, The bash code for showing a text like "80% charging" is like this:

echo "`cat /sys/devices/platform/smapi/BAT0/remaining_percent`"% "`cat /sys/devices/platform/smapi/BAT0/state`"

See my wmfs-status script here.

Battery notification script
I created a notification script that uses the notify-send command as part of a notification daemon (xfce4-notifyd or similar):

state=`cat /sys/devices/platform/smapi/BAT0/state`
if [ "$state" = 'discharging' ];
  then batt=`cat /sys/devices/platform/smapi/BAT0/remaining_percent`
  if (($batt <= 30));
    then if (($batt <= 10));
           then notify-send -u critical "Battery is low!
`acpi -b | tail -c 24 | head -c 10` remaining" ;
           else notify-send "Battery is critical!
`acpi -b | tail -c 24 | head -c 10` remaining" ;
         fi
  fi
fi


You can run this script  from your .xinitrc like:
 (while true; do sleep 300s; /home/cuh/bin/battwarning.sh; done) &

As a result you will be notified every 5 minutes when your battery goes below 30% and you get a critical warning when your voltage is under 10%.

See my full .xinitrc here.


Battery protection
Some parameters under /sys/devices/platform/smapi/BAT0/ can be set by writing to the files of this directory. For example you can force discharging the battery even if the power supply is plugged in (it can be useful when your battery is over the stop_charge_thresh, see below) by setting the force_discharge parameter to 1 (the default value is 0) by this command:

echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge

or you can set the battery charging thresholds for keeping the current capacity between 30% and 80% for protecting your LiIon battery from low and high percentages (see here) by setting the start_charge_thresh and stop_charge_thresh values. Unfortunately on my Thinkpad Edge 11 there seems to be a bug in this area because I cannot set both threshold limits. Changing one changes the other so that start_charge_thresh is always a higher value than the stop_charge_thresh (who understands...). Anyway, I do not really need to set the lower threshold level because when I am on DC power and my battery discharges I get a notification to plug in the power supply and if I am in a situation that I can plug it in I do it so. I limit the upper threshold to 80% to protect my battery from overcharging. To do so I put this line to my /etc/rc.local to set the threshold at every boot:

echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

HDD drop protection - not working on Edge 11
According to the tp_smapi documentation this package contains the hdaps driver as well, which is responsible for HDD protection against physical shocks by means of a built-in accelerometer's signals. After installing tp_smapi I loaded the module:

modprobe hdaps

The module is loaded but dmesg says:

thinkpad_ec: thinkpad_ec_read_row: failed requesting row: (0x01:0x00)->0xfffffff0

At the same time my battery status modules stopped working, I cannot access the contents of the /sys/devices/platform/smapi/BAT0 files.


I read that a temporary workaround might be to switch off my laptop, unplug the power supply, remove the battery and place it back after some minutes. Funny that this can be a workaround, but I faced the same with the malfunctioning Fn buttons, too (see below). This time it did not help, now I cannot even load the hdaps driver.

I tried to overwrite the native kernel hdaps driver by the tp_smapi driver:

mv /lib/modules/3.0-ARCH/kernel/drivers/platform/x86/hdaps.ko.gz /lib/modules/3.0-ARCH/kernel/drivers/platform/x86/hdaps.ko.gz_backup

cp /lib/modules/3.0-ARCH/extra/hdaps.ko.gz /lib/modules/3.0-ARCH/kernel/drivers/platform/x86/hdaps.ko.gz

and this time I got back to the loadable module with the dmesg warning and switched-off battery framework.

I looked around and some people say that the hdaps service is not available on this Thinkpad model, I can confirm this.

cpu_frequtils
See the details at www.thinkwiki.org.CPU scaling and profiling works fine on the Edge 11, the Extra repository contains the cpufrequtils package and the Arch Wiki is pretty helpful as usual. Instead of setting up your frequency scaling manually you can use Laptop Mode Tools, see below. After installing cpufrequtils and setting up LMT you only need to add acpi-cpufreq to your MODULES in /etc/rc.conf and edit the /etc/laptop-mode/conf.d/cpufreq.conf file to your taste.

Laptop Mode Tools
Laptop Mode Tools is a centralised power management solution featuring several power saving services. These services are controlled by only one daemon. In practice this means that you only need to install the laptop-mode-tools package, place laptop-mode to your DAEMONS list of your /etc/rc.conf and tune the power saving options as you like with the appropriate config files: /etc/laptop-mode/laptop-mode.conf and /etc/laptop-mode/conf.d/* . You can set up different CPU governors, different LCD brightness, auto switching off your WiFi antenna when idle, etc. features according to the actual power state (AC / DC) of your laptop. Installation and configuration is well described in the LMT Arch Wiki.

Strange bug of Thinkpad function buttons
Sometimes I have problems with the brightness and volume Fn buttons. They simply do not work. Nothing helps here, neither restarting daemons, nor rebooting the machine. Very strangely the only solution is to switch the laptop off, remove the battery and place it back after 5 secs, and boot up the machine again. I haven't faced this problem for a while, maybe a kernel upgrade (or who knows what) solved it permanently.

Synaptics touchpad
To fine-tune the touchpad you have to install the xf86-input-synaptics package and set up the options under /etc/X11/xorg.conf.d/10-synaptics.conf

With the default settings I had an odd problem with double taps that wanted to drag and drop elements instead of releasing the mouse click. I worked a lot to achieve a functioning, fast and responsive touchpad. My config looks like this:

Section "InputClass"
Identifier "touchpad catchall"
Driver "synaptics"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
Option "VertEdgeScroll" "on"
Option "VertTwoFingerScroll" "on"
Option "VertResolution" "100"
Option "HorizResolution" "100"
Option "MaxDoubleTapTime" "100"
EndSection

2 comments:

  1. Excellent: Tell me that desktop manager use. I used Archlinux with LXDE in a netbook lenovo. But I will wish use openbox or similar....


    Congratulationes for you.

    Julio Cesar

    ReplyDelete
  2. Hello Julio,
    I use awesome window manager actually. Soon I will write a detailed post about it.

    ReplyDelete