You are not logged in.

#1 2009-02-04 22:23:25

sokuban
Member
Registered: 2006-11-11
Posts: 412

Cannot resume from suspend when done with acpi (close lid)

This is my /etc/acpi/handler.sh

#!/bin/sh
# Default acpi script that takes an entry for all actions

# NOTE: This is a 2.6-centric script.  If you use 2.4.x, you'll have to
#       modify it to not use /sys

minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

set $*

case "$1" in
    button/power)
        #echo "PowerButton pressed!">/dev/tty5
        case "$2" in
            PWRF)   logger "PowerButton pressed: $2" ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB)   echo -n mem >/sys/power/state ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC)
                case "$4" in
                    00000000)
                        echo -n $minspeed >$setspeed
                        #/etc/laptop-mode/laptop-mode start
                    ;;
                    00000001)
                        echo -n $maxspeed >$setspeed
                        #/etc/laptop-mode/laptop-mode stop
                    ;;
                esac
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000000)   #echo "offline" >/dev/tty5
                    ;;
                    00000001)   #echo "online"  >/dev/tty5
                    ;;
                esac
                ;;
            CPU0)    
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        #echo "LID switched!">/dev/tty5
        /usr/sbin/pm-suspend
    ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

The only thing I added was the /usr/sbin/pm-suspend.

When I run /usr/sbin/pm-suspend from a terminal, the suspend works fine, but when I try to use the close lid suspend I have trouble resuming. When I open the lid, the laptop starts making noises and lights up (as if it were to resume), but after a while it goes and suspends again.

Pushing the power button to try to resume (this is how I successfully resumed from the commandline suspend) causes the same behavior to happen, so I ended up just holding down the power button and rebooting.

I tried commenting the /usr/sbin/pm-suspend, and uncommented the default echo line. This caused "LID switched!" to be displayed 3 times on /dev/tty5; each one on the next line further to the right. I'm not sure if that is supposed to be normal behaviour.

Offline

#2 2009-02-04 23:56:48

pointone
Wiki Admin
From: Waterloo, ON
Registered: 2008-02-21
Posts: 379

Re: Cannot resume from suspend when done with acpi (close lid)

The lid button is toggled both when the lid is opened and when the lid is closed. You need to add a check to see whether the lid is opened or closed, or use a more detailed case in your handler script.


M*cr*s*ft: Who needs quality when you have marketing?

Offline

#3 2009-02-05 05:12:59

kjon
Member
From: Temuco, Chile
Registered: 2008-04-16
Posts: 398

Re: Cannot resume from suspend when done with acpi (close lid)

the problem -in my opinion- is caused by laptop-mode-tools. Are you using it?, because I saw a line refering to it on your code.


They say that if you play a Win cd backward you hear satanic messages. That's nothing! 'cause if you play it forwards, it installs windows.

Offline

#4 2009-02-05 07:32:29

mihi
Member
Registered: 2009-01-27
Posts: 10

Re: Cannot resume from suspend when done with acpi (close lid)

Hi, I get two LID events. My section for suspending on lid close looks like this:

    if grep -q closed /proc/acpi/button/lid/LID0/state
    then
        logger "ACPI lid closed"
        /usr/sbin/pm-suspend
    else
        logger "ACPI lid opened"
        echo -n 2 > /proc/acpi/video/EGFX/LCD0/brightness
    fi

When I open the lid, I reset the brightness to 2.

HTH,
Michael

Last edited by mihi (2009-02-05 07:37:41)

Offline

#5 2009-02-05 12:05:39

sokuban
Member
Registered: 2006-11-11
Posts: 412

Re: Cannot resume from suspend when done with acpi (close lid)

@mihi

While that looks good, I'm not too sure where to put it.

I tried replacing these lines:

    button/lid)
        #echo "LID switched!">/dev/tty5
        /usr/sbin/pm-suspend

But then vim starts making things hilited in red, which scares me.

So then I tried replacing the whole /etc/acpi/handler.sh (I kept the set line and above, but removed everything else), and when I did that, nothing happened.

@kjon

I have laptop-mode-tools now. (But it is set off while on AC power and I did the tests with AC power.) However I first attempted this before I got laptop-mode-tools. I don't think it makes a difference. That is just my default config file.

Offline

#6 2009-02-05 12:13:27

mihi
Member
Registered: 2009-01-27
Posts: 10

Re: Cannot resume from suspend when done with acpi (close lid)

Hi, sorry my fault. I should have been more specific. Here my full handler.sh

#!/bin/sh
# Default acpi script that takes an entry for all actions

# NOTE: This is a 2.6-centric script.  If you use 2.4.x, you'll have to
#       modify it to not use /sys

minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

set $*

case "$1" in
    button/power)
        #echo "PowerButton pressed!">/dev/tty5
        case "$2" in
            PWRF)   logger "PowerButton pressed: $2"
                /usr/sbin/pm-suspend ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB)   logger "SleepButton pressed: $2"
                /usr/sbin/pm-suspend ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC)
                case "$4" in
                    00000000)
                        echo -n $minspeed >$setspeed
                        #/etc/laptop-mode/laptop-mode start
                    ;;
                    00000001)
                        echo -n $maxspeed >$setspeed
                        #/etc/laptop-mode/laptop-mode stop
                    ;;
                esac
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000000)   #echo "offline" >/dev/tty5
                    ;;
                    00000001)   #echo "online"  >/dev/tty5
                    ;;
                esac
                ;;
            CPU0)
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        #echo "LID switched!">/dev/tty5
        logger "ACPI lid switched $1 $2"
        if grep -q closed /proc/acpi/button/lid/LID0/state
        then
            logger "ACPI lid closed"
            /usr/sbin/pm-suspend
        else
            logger "ACPI lid opened"
            echo -n 2 > /proc/acpi/video/EGFX/LCD0/brightness
        fi
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

HTH.

Offline

#7 2009-02-05 12:30:10

sokuban
Member
Registered: 2006-11-11
Posts: 412

Re: Cannot resume from suspend when done with acpi (close lid)

Oh, I found out the actual problem. I had no /proc/acpi/button/lid/LID0/state, mine was just LID/state. Either way, I got it working now... kinda...

When I open the lid, the computer starts making noises and lighting up as if it were to resume, but then goes into standby again. Only now, if I tap the powerbutton it can sucessfully resume.

I also noticed that brightness doesn't save, it comes back with max brightness. I noticed you changed the brightness there, but the thing is, I don't always use the same brightness, so I wouldn't want to put a default brightness. It isn't so much of a problem because I could always just lower the brightness again though.

Last edited by sokuban (2009-02-05 12:33:09)

Offline

#8 2009-03-25 16:05:33

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: Cannot resume from suspend when done with acpi (close lid)

Thank you, sokuban!  The tip about having a /LID/state rather than a /LID0/state tipped me off. not is suspends and resumes properly.


Now all I need to do is arrange it so it only does this on battery, and just blanks the screen through xscreensaver when on AC and I would be totally happy.  Till I figure that out, suspending with every lid close is a good substitute.


(P.S. laptop-mode-tools has not made it any easier to differentiate suspend/lid closed on batter from suspend/lid closed AC...   perhaps there is a way to script this in the handler.sh, but I am not skilled enough at scripting yet to cobble the command together. I am not sure if I can nest lid states within the AC and battery state areas.)


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#9 2009-04-03 21:44:18

Lilith Complex
Member
From: Baltimore, MD
Registered: 2009-01-29
Posts: 3
Website

Re: Cannot resume from suspend when done with acpi (close lid)

Well, you could check /proc/acpi/ac_adapter/AC/state. Simple one-line file that contains the status of the AC adapter in your system. Now, how to code that, well, you're on your own. I couldn't code my way out of a wet paper bag!

There may also be a better option in /sys, but I'm a bit lazy to look for it  wink


'One is not born, but becomes a woman. No biological, psychological, or economic fate determines the figure that the human female presents in society.' -Simone de Beauvoir

Offline

Board footer

Powered by FluxBB