22 January 2010

Enabling Laptop mode tools on closing laptop lid

Laptop mode tools enables different laptop behaviors depending on power supply type (AC/DC) or battery level. I don't know why but in my Ubuntu (Karmic) it was disabled by default (as opposed to the comment in the file). In order to enable it, following line has to be changed in /etc/default/acpi-support:
ENABLE_LAPTOP_MODE=true
Then I started configuring the file /etc/laptop-mode/laptop-mode.conf and all the files in /etc/laptop-mode/conf.d/. There are many different options for various energy savings for various hardware, fortunately the files are well documented and everything is clear.

Enabling laptop mode when lid is closed
What I wanted in my configuration was to enable some settings when laptop lid is closed. When I close the lid I mean that the laptop is doing nothing or something not important and don't need its full power. Especially I wanted to slow down CPU in order to make it quiet even when some background tasks are being done. I found and configured correctly the file: /etc/laptop-mode/conf.d/cpufreq.conf configuring:
CONTROL_CPU_FREQUENCY=1
LM_AC_CPU_GOVERNOR=powersave
Then I edited again main configuration file /etc/laptop-mode/laptop-mode.conf:
 ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=1
To my surprise it didn't work.

Solving issue with lid closing detection
The laptop mode tools didn't react on lid close. In order to workaround this problem I edited ACPI scrpit: /etc/acpi/lid.sh adding following lines before [if [ `CheckPolicy` = 0 ]; then exit; fi] line

# pziemniak: enable laptop_mode
grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]
then
    laptop_mode start
else
    laptop_mode auto
fi
# pziemniak: enable laptop_mode end

In the code I just enable the laptop mode when lid is closed and disable when opened. Laptop_mode shouldn't be normally (by end user) executed this way but following the documentation it is allowed to call it from some handlers and scripts.
There might be some better solution where to put this code but I didn't have time to look for it. I also wanted to distinguish it in the file in order to prevent accidental overrides.

No comments:

Post a Comment