tp_smapi = HDD protection + battery control + laptop insted of joystick

Wed, 19 May 2010 (tags:linux)
So to get all working you need 2.6.32 kernel. Why 2.6.32 kernel? Because the Intel 5300 support is there already build in and in Debian default 2.6.26 you will be struggling to get it working and as well from 2.6.28 the hdaps_protect patch is not needed anymore. The libata driver is doing the disk head parking and queue freezing for you. And the vmware-tools are compiling without any problem with VMware 7 (if not, try updated version 7.0.1). So The 2.6.32 from back-ports it's not so bad choice.
 

 
 
sudo su
apt-get install linux-source-2.6.32
 
cd /usr/src/
tar xzvf linux-source-2.6.32.tar.bz2
cd linux-source-2.6.32
make menuconfig
 
 
in the menu config I changed the "Processor family" to "Core 2/ newer Xeon" instead of "Generic-x86-64" to get little bit better optimizations
 
make-kpkg --initrd kernel_image --append-to-version moje
dpkg -i ../linux-image-2.6.32moje_2.6.32moje-10.00.Custom_amd64.deb
 
reboot into the new kernel
 
get ready to reinstall Nvidia drivers (for 2.6.32 you need gcc-4.3 and for 2.6.26 gcc-4.1)
 
With new running kernel...
 
wget http://downloads.sourceforge.net/project/tpctl/tp_smapi/0.40/tp_smapi-0.40.tgz?use_mirror=ovh
tar xzvf tp_smapi-0.40.tgz
cd tp_smapi-0.40
make install HDAPS=1
echo options hdaps invert=6 >> /etc/modprobe.d/options
 
this will invert the axis to show corect possition in hdaps-gl
 
if you want you can make patch for kernel
 
make patch
patch -p1 -d /lib/modules/2.6.32moje/source
 
and then when compiling kernel you can enable
ThinkPad SMAPI Support (TP_SMAPI) [N/m/y/?] (NEW)
 
as module and you don't have to compile this module seperately, it will be done together with kernel
 
now you can just
 
modprobe tp_smapi
 
and it should be avaible in sysfs /sys/devices/platform/hdaps
 
The debian deamon hdapsd could not see it anyway so I get it from sources
 
wget http://downloads.sourceforge.net/project/hdaps/hdapsd/hdapsd-20090401/hdapsd-20090401.tar.gz?use_mirror=kent
 
tar xzvf hdapsd-20090401.tar.gz
cd hdapsd-20090401
./configure
make
make install
 
create /etc/init.d/hdapsd2 file:
kill -9 `pidof hdaspd`
sleep 1
hdapsd -s 9 -b
 
the -s 9 is sensitivity, smaller number is more sensitive, when the -d is not used then it will autodetect HDDs and the autodetection is working pretty good and it got both drives (the default script I think is working just with 1). The -b is for deamon working in background.
 
create in /etc/rc2.d/S20hdapsd symlink to the init.d folder and it should be working :)
 

Battery control 

 
echo "tp_smapi" >> /etc/modules
echo "hdaps" >> /etc/modules
update-initramfs -u
modprobe -a tp_smapi hdaps
echo 30 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
cat /sys/devices/platform/smapi/BAT0/*_charge_thresh 
 
 
#force discharge
echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge
 
 
#to keeep settings edit /etc/sysfs.conf
devices/platform/smapi/BAT0/start_charge_thresh = 50
devices/platform/smapi/BAT0/stop_charge_thresh = 80
 
To get nice KDE applet download kthinkbat
 
wget http://lepetitfou.dyndns.org/download/kthinkbat/src/kthinkbat-0.2.x/kthinkbat-0.2.9.tar.bz2
tar xzvf kthinkbat-0.2.9.tar.bz2
cd kthinkbat-0.2.9
./configure
make
make install
 
And now you can find it between another KDE applets just waiting to get added on panel.
 
To get text information get thinkpad-smapi.sh from ThinkWiki website:
 
wget http://www.thinkwiki.org/index.php?title=Code/thinkpad-smapi.sh&action=raw&ctype=application/octet-stream
 
 

 

Joystick

Now it should be working, just go to the control panel and look on the joystick. Now just tilt laptop and you can play tux racers... You have the accelerometer data available as joystick as well but try image how you could play games with that :) :) :)