[SOLVED][ltp] T30 ACPI Sleep on Lid Close
Michael B Allen
linux-thinkpad@linux-thinkpad.org
Fri, 13 May 2005 19:07:45 -0400 (EDT)
Michael B Allen said:
> What is the proper method for handling suspend/resume on a T30?
I think I have this licked. I've been taking notes in anticipation of
maybe adding content to thinkwiki.org. Here's what I've come up with.
With the introduction of ACPI there are more things under programmatic
control. Sleeping is one of those things. To sleep the T30 manually is
simple. You just do:
echo -n "mem" /sys/power/state
However there are two problems with this. It doesn't happen automatically
when you close the lid and it does not turn off the LCD backlight. The
acpid daemon is provided to solve the first problem. By adding an event
handler you can run a script in response to both closing the lid and
pressing Fn-F4 (suspend on the T30). You just need to create a file in
/etc/acpi/events like the following:
$ cat /etc/acpi/events/sleep
event=button/(sleep|lid)
action=/etc/acpi/actions/sleep %e
The "event" line is a regular expression specifying the events we're
interested in. I determined what the event strings are from looking at
/var/log/acpid after trying to suspend, close the lid, etc. What I found
was that when the Fn-F4 key sequence is selected a "button/sleep" event is
dispatched. Closing and opening the lid both yield "button/lid" events.
Note that if you add or modify one of these events files you must kill
-SUGHUP <pidofacpid>.
The "action" line is the command to be executed when these events are
dispatched. In this example I call a script and pass the event description
text using the builtin %e macro. The /etc/acpi/actions/sleep script is as
follows:
#!/bin/sh
if [ "$1" = "button/sleep" ] || \
grep -q closed /proc/acpi/button/lid/${2}/state
then
chvt 6;
/usr/sbin/radeontool light off;
echo -n "mem" > /sys/power/state;
chvt 7;
fi
Translated this reads -- if the event is a sleep event (meaning Fn-F4 was
triggered) or the state of the lid is closed, then switch to a virtual
console, turn off the backlight, and goto sleep. When we wake up, switch
back to X.
Note that the echo line does not return until we are revived. So there is
only one event generated and there is no need to check the state of
anything. This is unlike the lid which generates an event for both opening
and closing thus requiring that we check it's state and only act if it's
closed.
Unfortunately this will not work for a wide range of machines. For some
machines it may be sufficient to turn off the backlight using 'xset dpms
force off' (for this to even do anything for me with FC3 I had to use 'su
miallen -c "xset -display :0 dpms force off"'). But for whatever reason,
when the T30 starts to sleep, it switches to console mode which causes the
backlight to come back on. So my solution above is to preemptively switch
to console mode and turn off the backlight so that doesn't happen. However
now, we cannot use xset because it's an X program that has no bearing on
the console. Fortunately I happenstanced across radeontool which
communicates directly with the T30 radeon mobility and therefore works
from the console.
Altogether these two files and radeontool make sleeping the T30 when you
close the lid or hit Fn-F4 work as expected.
Mike
>
> I just installed Fedora Core 3 to find the machine no longer suspends when
> I close the lid. After a little googling I see it has to do with ACPI.
> Indeed if I modify /etc/grub.conf to read:
>
> ... rhgb quiet acpi=off
>
> it suspends when I close the lid just as it did with my old RH 7.3
> install.
>
> But I do not want to be the exception or I might run into exceptional
> things so I'm wondering if ACPI suspend can be made to work as nicely as
> it does with APM. If I do:
>
> echo 3 > /proc/acpi/sleep
>
> It appears to suspend the machine but the backlight stays on. I've seen
> some funky scripts using "radeontool" to turn off the backlight and
> suspend but this still doesn't tie-in lid events.
>
> Has anyone devised a solid method for suspending and resuming when closing
> and opening the lid on a T30?
>
> If not, can someone give me pointers for the interfaces involved? I am a
> competent C programmer and I would be happy to develop a small utility to
> handle all of this stuff as transparently as possible.
>
> Thanks,
> Mike
> --
> The linux-thinkpad mailing list home page is at:
> http://mailman.linux-thinkpad.org/mailman/listinfo/linux-thinkpad
>
>