You are not logged in.

#1 2008-03-04 05:48:08

ph0tios
Member
Registered: 2008-02-23
Posts: 126

s2ram question

s2ram works great with my laptop, but I was wondering how I could configure it to run when I close my laptop lid. I use awesome so there is no program like in kde that I can tell to do it. I'm sure it's simple..I'm just a little dense when it comes to these things.:P

Offline

#2 2008-03-04 06:24:56

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: s2ram question

If you use acpid daemon you can add the "s2ram" command to the appropriate section in the /etc/acpi/handler.sh file.  I don't remember exactly, but there should be a case statement there with "button/lid)" or something -- that's where the command needs to be added.

Offline

#3 2008-03-04 07:58:49

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

Try something like the following:

    button/lid)
        case $2 in 
            LID) 
                grep -q closed /proc/acpi/button/lid/*/state
                if [ $? = 0 ]; then
                    s2ram
                fi
                ;;
            *)   ;;
        esac
        ;;

in your /etc/acpi/handler.sh script. I use this and it works great. Note the grep and if... are there to make sure that suspend is only called when the lid is shut. If you remove these your machine will wake and re-suspend when you open your lid since opening the lid activates this same ACPI event.

Good luck,
j

Offline

#4 2008-03-04 16:06:12

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

J,

I just tried your method. It doesn't appear to be working for me. sad Hm.

Offline

#5 2008-03-04 16:10:33

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: s2ram question

ph0tios wrote:

J,

I just tried your method. It doesn't appear to be working for me. sad Hm.

Try removing the conditional statement altogether and using something like this:

    button/lid)
        case $2 in 
            LID) 
                s2ram
                ;;
            *)   ;;
        esac
        ;;

This is, more or less (I use a custom script for suspending) the way my laptop is set up, and it works very reliably.  By the way -- you need to restart acpid daemon after making changes to the handler.sh file.

Offline

#6 2008-03-04 16:41:02

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

Hm, well that's bizarre. That didn't work either. I restarted the daemon and everything. I know it's not the s2ram command, because it works fine if I initialize it manually.

Offline

#7 2008-03-04 16:44:33

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: s2ram question

Something must be wrong -- maybe your laptop does not report lid events correctly (it happens on some laptops).  You can have a look at dmesg to see what (if anything) happens when you close the lid, maybe it'll give you some clues about what is wrong.

Offline

#8 2008-03-04 17:16:18

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

fwojciec wrote:

Something must be wrong -- maybe your laptop does not report lid events correctly (it happens on some laptops).  You can have a look at dmesg to see what (if anything) happens when you close the lid, maybe it'll give you some clues about what is wrong.

Well, this may be the root of a totally different problem, but dmesg outputs:

atkbd.c: Unknown key released (translated set 2, code 0x8d on isa0060/serio0).
atkbd.c: Use 'setkeycodes e00d <keycode>' to make it known.

over and over again. I noticed it does that when I first boot up as well. Maybe it could be interfering with it.


Also, opening the lid resumes from s2ram without any tweaking.

Offline

#9 2008-03-04 18:45:02

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

I think there are three possibilities here. Either your LID switch isn't picked up by the kernel, your ACPI implementation uses some slightly different arguments, or you made a mistake modifying handler.sh and the case labels are not in the right place..

First do an lsmod and be sure that you see the module button loaded. I believe the Arch default kernel will properly load this module, so it shouldn't be a problem, but check it nonetheless. If it is not being loaded automatically you can add button to the MODULES line of your /etc/rc.conf file.

Second, to be sure about the events your ACPI is generating, do

tail -f /var/log/acpid.log

then open and close your lid to see what events ACPI is generating. You should see something like the following:

Mar  4 08:47:56 yemaya acpid: received event "button/lid LID 00000080 00000010"

If you see something other than "button/lid" and "LID" for the first two arguments, you will have to adjust the case labels in your handler.sh accordingly.

Last, for reference purposes, here is the handler.sh I use. It is just a customized version of the original Arch script. I modified some of the events (my laptop generates button/sleep SBTN, not button/sleep SLPB) and some stuff to switch governors on AC power changes. Anyway here is the script:

#!/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|SBTN) pm-suspend ;;
            *)    logger "ACPI action undefined: $2" ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC)
                case "$4" in
                    00000000)
                        cpufreq-set -g conservative
                        ;;
                    00000001)
                        cpufreq-set -g ondemand
                        ;;
                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)
        case $2 in 
            LID) 
                logger "button/lid [$1] [$2] [$3] [$4]"
                grep -q closed /proc/acpi/button/lid/*/state
                if [ $? = 0 ]; then
                    pm-suspend
                fi
                ;;
            *)   ;;
        esac
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

I don't think that the atkbd.c messages you are seeing are related to your lid problems, since ACPI handles lid events and not the keyboard driver. This probably means your keyboards has some extra "special" keys not known to the kernel.

Lastly, you are correct. You need not do anything to get a laptop to resume from suspend when the lid opens, this is apparently automatically handled by ACPI. It's getting it to suspend in the first place that is the trick.

Good luck and regards,
j

Offline

#10 2008-03-04 21:01:26

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

Hey J,

Thanks for taking the time to help with me this.

Button is there in lsmod. When I shut the lid and open it back up I get this:

Mar  4 15:59:15 galatia acpid: received event "button/lid LID 00000080 0000000b"
Mar  4 15:59:15 galatia acpid: notifying client 7047[82:82]
Mar  4 15:59:15 galatia acpid: notifying client 7079[0:100]
Mar  4 15:59:15 galatia acpid: executing action "/etc/acpi/ati-powermode.sh"
Mar  4 15:59:15 galatia acpid: action exited with status 0
Mar  4 15:59:15 galatia acpid: executing action "/etc/acpi/handler.sh button/lid LID 00000080 0000000b"
Mar  4 15:59:16 galatia acpid: action exited with status 2
Mar  4 15:59:16 galatia acpid: completed event "button/lid LID 00000080 0000000b"
Mar  4 15:59:19 galatia acpid: received event "button/lid LID 00000080 0000000c"
Mar  4 15:59:19 galatia acpid: notifying client 7047[82:82]
Mar  4 15:59:19 galatia acpid: notifying client 7079[0:100]
Mar  4 15:59:19 galatia acpid: executing action "/etc/acpi/ati-powermode.sh"
Mar  4 15:59:19 galatia acpid: action exited with status 0
Mar  4 15:59:19 galatia acpid: executing action "/etc/acpi/handler.sh button/lid LID 00000080 0000000c"
Mar  4 15:59:19 galatia acpid: action exited with status 2
Mar  4 15:59:19 galatia acpid: completed event "button/lid LID 00000080 0000000c"

-Levi

Offline

#11 2008-03-05 04:14:30

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

OK, it looks like everything should be fine. You've got the right module loaded, your ACPI is generating button/lid events with the expected LID action. The oddness is that "action exited with status 2" line that appears. It would appear that there is something wrong with your handler.sh script. How about posting that (handler.sh) so we can make sure there are no errors in it. The only other option is that something is trying to run and failing. Seeing handler.sh will tell us.

Regards,
j

Offline

#12 2008-03-05 04:36:34

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

Here we go:



#!/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)
        case $2 in
           LID)
                      s2ram
               fi
                  ;;
              *)     ;;
               esac
               ;;

Offline

#13 2008-03-05 06:10:55

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

Right below s2ram you have a stray "fi". Remove it and then try closing your lid. It also seems that the end of the big enclosing case statement has been cut off. The end of your file should look like:

    button/lid)
        case $2 in
            LID) s2ram ;;
            *) ;;
        esac
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

Good luck,
j

Offline

#14 2008-03-05 06:22:21

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

Hey J,
thanks a lot for all your help! That fixed it.

I was also wondering...is it harmful to leave it suspended to ram for long periods of time? Say, I didn't shut my laptop off for weeks. I just would suspend to ram when I wasn't using it(and of course plugged in so the battery didn't die).


thanks again,
Levi

Last edited by ph0tios (2008-03-05 07:34:59)

Offline

#15 2008-03-05 21:26:17

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

I'm glad to hear it works now. Does it resume properly when you open the laptop? If so then you are all set.

As far as I know (which is pretty far, I think) it is not harmful to suspend for long periods of time. I do this with my laptop. I don't think I've turned it off in a couple of months. I open the screen in the morning to start working and shut it to suspend to RAM when I'm done.

Regards,
j

Offline

#16 2008-03-05 21:48:18

ph0tios
Member
Registered: 2008-02-23
Posts: 126

Re: s2ram question

jbromley wrote:

I'm glad to hear it works now. Does it resume properly when you open the laptop? If so then you are all set.

As far as I know (which is pretty far, I think) it is not harmful to suspend for long periods of time. I do this with my laptop. I don't think I've turned it off in a couple of months. I open the screen in the morning to start working and shut it to suspend to RAM when I'm done.

Regards,
j

Yeah, it resumes properly. One thing though, when it resumes for a short moment these white and black lines will flash on the screen. Maybe it is the video card initializing? If it's not fixable, it's not a big deal...it works fine regardless.

Offline

#17 2008-03-05 22:28:39

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: s2ram question

Yes, the black and white lines are probably the result of the video card starting up. Perhaps s2ram has a way of doing a video state restore on resume or something like that to minimize the lines. Unfortunately I don't really know anything about s2ram so I cannot help you there.

Regards,
jay

Offline

#18 2008-03-06 03:16:11

SpookyET
Member
Registered: 2008-01-27
Posts: 410

Re: s2ram question

Try pm-utils-opensuse from AUR.

Offline

#19 2008-10-05 10:34:46

ippo76
Member
From: PL
Registered: 2008-10-05
Posts: 5

Re: s2ram question

Hi, it`s my first time... smile

I`ve fujitsu-siemens lifebook. I`ve laptop-mode-tools and pm-utils. Suspend and hibernate works, but lid close does not work sad
I`ve tried trick above, but no sucsess. I`m thinking, problem is between pm-utils and laptop-mode:
My /etc/acpi/handler.sh is

         button/lid)
                #echo "LID switched!">/dev/tty5
                ;;
        *)
                logger "ACPI group/action undefined: $1 / $2"
                ;;
esac

Paste /usr/sbin/pm-utils does not work.

My /etc/acpi/actions/lm_lid.sh :

 
#! /bin/sh

test -f /usr/sbin/laptop_mode || exit 0

# lid button pressed/released event handler

/usr/sbin/laptop_mode auto

Change for

 #! /bin/sh
/usr/sbin/pm-suspend

doesn`t work.
I`ve tried change /etc/laptop-mode/laptop-mode.conf and /usr/sbin/;aptop_mode

 ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=

both 0 nad 1 but no results.

I`m happy for my Arch, but lid close make me angry...

PS. Sorry for my "english" smile

Offline

#20 2008-10-06 06:37:13

BKJ
Member
Registered: 2008-09-19
Posts: 71

Re: s2ram question

@ippo76 I have the same tools installed and what I had to do was this:

back up this file:

/etc/acpi/actions/lm_lid.sh

then edit the file you just backed up and paste this code (completely replacing everything in the original file):

#!/bin/bash

export XAUTHORITY="$( ps -C xinit | tail -n 1 | sed -r 's/^.* -auth ([^ ]) .*$/\1/g' )"
export DISPLAY=":0.0"

powerstate=$(gawk '{print $2}' /proc/acpi/ac_adapter/AC/state);
lidstate=$(gawk '{print $2}' /proc/acpi/button/lid/LID/state);
case "$lidstate" in
        open)
                /usr/bin/xset dpms force on
                if [[ -n "$XAUTHORITY" ]]
                then
                    if [[ "$powerstate" == "on-line" ]]
                    then
                        logger -t acpid "unthrottling xscreensaver"
                        /usr/bin/xscreensaver-command -unthrottle &> /dev/null
                    fi
                fi
                ;;
        closed)
                /usr/bin/xset dpms force off
                if [[ -n "$XAUTHORITY" ]]
                then
                    if [[ "$powerstate" == "on-line" ]]
                    then
                        logger -t acpid "throttling xscreensaver"
                        /usr/bin/xscreensaver-command -throttle &> /dev/null
                    fi
                    /usr/bin/xscreensaver-command -lock &> /dev/null
                fi
                ;;
esac

Then add this to your .bashrc file:

xhost +local:root > /dev/null

This was the only way I could get mine to work. I also wanted my screen to lock when the lid was closed. 

You may need to install xscreensaver if it is not already installed if you want your screen to lock.  Also, I am not sure how secure this is (the .bashrc method) as it is mentioned on the Gentoo wicki but like I said this was the only way that it worked for me.

Also, to test without logging out simply do the above and then run this under your normal user account: xhost +local:root > /dev/null

The solution I am providing came from the Gentoo wicki: http://gentoo-wiki.com/HOWTO_Automatica … ur_monitor

NOTE:  This will only blank and lock your screen when the lid is closed.

EDIT:

After retracing my steps it looks as though I had to edit this file as well: /etc/acpi/handler.sh and add a line to the button/lid statement (towards the bottom):

/usr/bin/xscreensaver-command -lock

so it now looks like this

button/lid)
                #echo "LID switched!">/dev/tty5
                /usr/bin/xscreensaver-command -lock
                ;;

Last edited by BKJ (2008-10-06 10:25:51)

Offline

#21 2008-10-06 17:18:59

ippo76
Member
From: PL
Registered: 2008-10-05
Posts: 5

Re: s2ram question

@BKJ
Thanks, I`ll try this solution if I`ll have free time smile

PS. I have xscreensaver, but I want hibernate closing lid

Offline

Board footer

Powered by FluxBB