Thursday, January 10, 2008

IBM ACPI

Nice thing with IBM Thinkpad (now Lenovo) laptops is ibm-acpi linux kernel module. You can access many sensors and laptop properties by simply reading and writing files in /proc/acpi/ibm. For example, you can turn the thinklight on the top of the laptop on/off with:
echo on > /proc/acpi/ibm/light
echo off > /proc/acpi/ibm/light
For commands that specific file accepts, just display it with cat. Very interesting file is thermal, which displays temperatures read from sensors scattered all over your laptop. You can also see/set fan speed with file fan. Here is a perl script I wrote for quickly displaying laptop temperatures and fan speed. Please note that number of temperatures displayed in thermal file changed in linux kernel 2.6.18, so before running this script make sure you have the newest kernel and loaded ibm-acpi module.

#!/usr/bin/perl
# (C) 2007 Igor Pozgaj

use strict;
use warnings;

open (IF, "</proc/acpi/ibm/thermal") or die "No ibm-acpi module found";
close(IF);
my %t = (
"CPU" => $values[1], # CPU
"PCI" => $values[2], # Mini-PCI
"HDD" => $values[3], # Internal hard disk
"BAT1" => $values[5], # main battery, primary sensor (under F5)
"BAT2" => $values[7], # main battery, secondary sensor (under Home)
"MCH" => $values[9], # northbridge, to DRAM bus (above track point)
"ICH" => $values[10], # southbridge (under touchpad)
"PWR" => $values[11], # power regulator (under F2 key)
);


open(IF, "</proc/acpi/ibm/fan") or die "No ibm-acpi module found";
my $fan = (split(/:\s+/, $line[0]))[1];
close(IF);

write;

format STDOUT_TOP=
Thermal data for IBM

CPU PCI HDD BAT1 BAT2 MCH ICH PWR FAN
--------------------------------------------------------------------------
.

format STDOUT=
@## °C @## °C @## °C @## °C @## °C @## °C @## °C @## °C @#### rpm
$t{"CPU"}, $t{"PCI"}, $t{"HDD"}, $t{"BAT1"}, $t{"BAT2"}, $t{"MCH"}, $t{"ICH"}, $t{"PWR"}, $fan
.

0 comments: