使用ACPI功能,需要用到button和battery模块。button模块监视电源开关键(power button)、屏幕开合状态键(lid button)和休眠键(sleep button)的状态,并根据状态的变化运行设定的程序;battery则让用户可以监视电池的状态。Slackware启动时没有加载加载这两个模块,需要手工在 /etc/rc.d/rc.modules 里面增加 /sbin/modprobe/button 和 /sbin/modprobe battery 。
加载button之后,按照默认设定,可以实现按电源开关键自动关机的功能。
下面介绍一下通过屏幕开合状态键(lid button)实现suspend to RAM的做法(系统采用的是slackware 10.1 的testing目录中编译好的2.6.10版内核及内核模块):
首先,控制台(console)需要使用640x480的分辨率,即在lilo.conf里面不要设置 vga=xxx 这个选项,原因稍后再提。
第二,从suspend状态“醒来”的时候,需要一个叫做video_post的小工具来“唤醒”屏幕显示。
用浏览器访问这个页面,点击video_post tool from Venki,会下载一个attachment.cgi文件,这实际上是个tar.gz文件,mv attachment.cgi video_post.tar.gz,解开它并用make命令编译,将得到 video_post,然后 cp video_post /etc/acpi
第三,建立一个脚本文件lidbtn.sh,并cp到 /etc/acpi/,内容是:
#!/bin/bash
#查看lid button的状态
lid_state=/proc/acpi/button/lid/LID0/state
#状态没有变化则退出
test -e $lid_state || exit 0
#若测试到屏幕合上,则开始suspend to RAM的操作
if cat $lid_state | grep closed > /dev/null
then echo "lid closed -> suspending"
/etc/rc.d/rc.inet1 stop #停止网络连接
rmmod ipw2200 #卸载无线网卡驱动
rmmod b44 #卸载有线网卡驱动
rmmod uhci_hcd
echo "mem" > /sys/power/state #suspend to RAM
/etc/acpi/video_post #唤醒屏幕显示
modprobe uhci_hcd #唤醒外接usb鼠标
modprobe ipw2200 #重新加载网卡驱动
modprobe b44
/etc/rc.d/rc.inet1 restart #重新启动网络连接
else echo "lid opened -> resuming"
fi
第四,设置acpi事件,当发现lid switch被按下时执行lidbtn.sh脚本
编辑 /etc/acpi/acpi_handler.sh,内容为:
#!/bin/sh
# Default acpi script that takes an entry for all actions
IFS=${IFS}/
set $@
case "$1" in
button)
case "$2" in
power) /sbin/init 0
;;
lid) /etc/acpi/lidbtn.sh #新添加
;; #新添加
*) logger "ACPI action $2 is not defined"
;;
esac
;;
*)
logger "ACPI group $1 / action $2 is not defined"
;;
esac
回过头来说说为什么console要保持640x480的分辨率。假如不用video_post的话,系统“醒来”的时候,屏幕上没有显示,这是内核还没有解决的一个bug。使用video_post之后,它只能在console设成640x480时才比较正常。如果在X状态下进入休眠,“醒来”时图形界面可能会显示混乱,此时用 ctrl+alt+f1 切换到控制台再用 ctrl+alt+f7 切换回来,显示就正常了。如果console用其它分辨率,X的鼠标指针会消失,但鼠标的功能还能正常使用,非常奇怪。
- ieee1394接口,没有相应的设备,无法测试其是否能在Linux中正常使用。
- PCMCIA接口,没有相应设备,无法测试。
- 机器上的SD读卡器,系统默认不能识别,经上网搜索没有找到相应的驱动,无法使用。
- ACPI的其它功能的使用尚需进一步学习和测试。
参考资料:
[1]Dell 700m with Debian Sarge,http://www.celifornia.com/documents/dell700m.html
[2]gentoo install on dell inspiron 700m,http://alien.dowling.edu/~petko/my_how-tos/dell_inspiron_700m.html
补充资料:
[1]Slackware and a Dell 700m,http://decompiled.org/howto/slackware700m.html
[2]Slackware 10.1 on a Dell 700m Laptop,http://www.rippleweb.org/index/site/projects/slack-on-700m
