# Acpid + swsusp2 on laptop - events & configs

## Vertical

Hello!

Today I installed 2.6.11 kernel with software suspend 2 + hibernate on Fujitsu-Siemens P7010 laptop

Also, I installed acpid. Now I'm trying to get acpid+swsusp2 with hibernate to work.

First, I mentioned that acpi doesn't detect status of thermal_zone & fan in /proc/acpi. Is it normal for P7010? I found acpi patches here http://acpi.sourceforge.net/ , but didn't try them, 'cause still they are not aviable for 2.6.11. Are they worth trying? Will kernel detect fan & thermal status?

Also, I'm looking for information for acpid + swsusp2 for notebook (lid & power button events). Great howto is located here: http://csd.informatik.uni-oldenburg.de/~eagle/acpid.html , but, unfortently it's configured for swsusp, not for swsusp2. I tried it, powerbutton event worked only for shutdown, but lid didn't.

So, if anyone has link or information about this stuff, this thread will be good place  :Smile: 

Thanks

ps Sorry for bad english

----------

## noneckturtle

Vertical,

I have an ASUS A2400H laptop with acpi and SWSUSP2 working.

Resources to check out are:

[url]https://forums.gentoo.org/viewtopic-t-80077-highlight-acpi+scripts.html[/url] Contains some good scripts for handling acpi enents.

[url]https://forums.gentoo.org/viewtopic-t-122145-highlight-acpi+scripts.html[/url] Good to check if you have buggy acpi.

[url]http://www.gentoo.org/doc/en/power-management-guide.xml[/url] The Gentoo Power Management Guide

I use a combination of all that gives the most flexibility.

Here is my /etc/acp/action.sh script. It has been customized to use the laptop function keys for my laptop. I use a 2.6 kernel because it contains the laptop-mode patch. I did have Swsusp2 working until I recently upgraded my kernel to gentoo-dev-sources-2.6.11-r7. 

#!/bin/bash

#

# /etc/acpi/action.sh

# should be called by acpid for all ACPI events

# Christopher Knoerle <cknoerle@gmx.net>

# 2004.02.27

# This works with gentoo-sources, ac-sources, mm-sources on my

# HP Compaq nx9000 Laptop. For more information have a look at

#   http://cknoerle.homelinux.org/nx9000/

# The latest version is available from

#   http://cknoerle.homelinux.org/nx9000/stuff/acpi/

# This should be placed in /etc/acpi/action.sh and should be called by acpid.

# To make this happen you need the acpid installed and running.

# acpid can be obtained from http://acpid.sourceforge.net

# For this to work you need only one event handler in /etc/acpi/event

# It should contain something like the following:

#event=.*

#action=/etc/acpi/action.sh %e

#

# To perform some checks at boot time you should call this script

# from your init scipts with the parameter 'on_boot'.

# When running Gentoo you can achieve this by doing the following:

#echo "/etc/acpi/action.sh boot_check" >> /etc/conf.d/local.start

# For speedstepping the cpu I use powernowd, which can be obtained from

#   http://www.deater.net/john/powernowd.html

# I have written a very basic initscript for Gentoo, which you can find at

#   http://cknoerle.homelinux.org/nx9000/stuff/

# For even better saving of battery power use a kernel with laptop-mode

# (see http://kerneltrap.org/node/view/653) and the laptop-mode shell-script

# which you can find at http://cknoerle.homelinux.org/nx9000/stuff/

# some paths to executables

LOGGER="/usr/bin/logger -t ACPID" # logs to syslog - an echo logs to /var/log/acpid

LAPTOPMODE="/sbin/laptop-mode"

HDPARM="/sbin/hdparm"

PIDOF="/bin/pidof"

XGAMMA="/usr/X11R6/bin/xgamma"

XSET="/usr/X11R6/bin/xset"

DCOP="$KDEDIR/bin/dcop"

HIBERNATE="/usr/local/sbin/hibernate"

# some paths in /proc

AC_STATE="/proc/acpi/ac_adapter/AC/state"

BAT_STATE="/proc/acpi/battery/BAT0/state"

BAT_INFO="/proc/acpi/battery/BAT0/info"

CPU_LIMIT="/proc/acpi/processor/CPU0/limit" # not needed with powernowd

LID_STATE="/proc/acpi/button/lid/LID/state"

# network control scripts

PCMCIA_CONTROL="/sbin/cardctl"

PCMCIA_CARD=""

PCMCIA_CARD_STATUS=""

# If we didn't know about an event log to /var/log/acpid to do something like

# grep "####" /var/log/acpid

no_action ()

{

	echo "#### NO ACTION FOR EVENT: $*"

	exit 1

}

# AC Adapter plugged in

acad_in ()

{

	$LOGGER "AC Adapter plugged IN"

	if $PIDOF X; then

		$XGAMMA -gamma 1.0 # set gamma in X to 100%

		$XSET dpms 0 0 600 # shutdown display after 600s

	fi

	$LAPTOPMODE stop # stop laptop-mode

	$LOGGER "Stopping Laptop-mode"

	$HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min

	$HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM

	# not needed with kernel 2.6.x - use powernowd

	#echo -n 0:0 > $CPU_LIMIT # set cpu performance state 0, throttling to 0

	# If 3Com 574B PC-Card installed re-enable 

        PCMCIA_CARD=$(gawk -F'"' '/PRODID_2/ { print $2 }' <($PCMCIA_CONTROL info))

        if ( PCMCIA_CARD='3C589' || PCMCIA_CARD='Megahertz 574B' ); then

                $PCMCIA_CONTROL resume

                $LOGGER "3Com PCMCIA resumed."

        fi

}

# AC Adapter plugged out

acad_out ()

{

	$LOGGER "AC Adapter plugged OUT"

	if $PIDOF X; then

		$XGAMMA -gamma 0.6 # set gamma in X to 70%

		$XSET dpms 0 0 120 # shutdown display after 120s

	fi

	$LAPTOPMODE start # start laptop-mode

	$LOGGER "Starting Laptop-mode"

	$HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s

	$HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM

	# not needed with kernel 2.6.x - use powernowd

	#echo -n 1:0 > $CPU_LIMIT # set cpu performance state 1, throttling to 0

	# If 3Com 574B 10/100 PC-Card installed suspend (power saving) (use onboard NIC instead)

	PCMCIA_CARD=$(gawk -F'"' '/PRODID_2/ { print $2 }' <($PCMCIA_CONTROL info))

	if (PCMCIA_CARD='3C589' || PCMCIA_CARD='Megahertz 574B'); then

		$PCMCIA_CONTROL suspend

                $LOGGER "3Com PCMCIA Suspended."

	fi

}

# BATTERY changed state

# Shutdown if battery capacity is low.

battery ()

{

	if grep -q discharging $BAT_STATE; then

		BAT_REMAIN=$(awk '/remaining/ { print $3 }' $BAT_STATE)

		BAT_WARNING=$(awk '/warning/ { print $4 }' $BAT_INFO)

		BAT_CRITICAL=$(awk '/low/ { print $4 }' $BAT_INFO)

		if (( $BAT_REMAIN <= $BAT_CRITICAL )); then

			$LOGGER "BATTERY capacity is CRITICAL"

			#btn_pwr

			$LOGGER "System Hibernating"

			$HIBERNATE

		elif (( $BAT_REMAIN <= $BAT_WARNING )); then

			$LOGGER "BATTERY capacity is LOW"

		fi

	fi

}

# POWERBUTTON pressed

# If kde is running try to show dialog - else shutdown immediately

btn_pwr ()

{

	$LOGGER "POWERBUTTON pressed"

	#if [ -x $DCOP ]; then

	if $DCOP --list-sessions --all-users &> /dev/null; then

		$LOGGER "KDE running: asking users what to do"

		$DCOP --all-users ksmserver ksmserver logout 1 2 0

	else

		$LOGGER "SHUTDOWN initiated"

		/sbin/init 0

	fi

}

# SLEEP button pressed

btn_sleep ()

{

	$LOGGER "SLEEP button pressed"

	$LOGGER "System Hibernating"

	$HIBERNATE

}

# LID closed/opened

# Anything useful to do when lid is closed/opened?

btn_lid ()

{

	if grep -q open $LID_STATE; then

		$LOGGER "LID opened"

		$PCMCIA_CONTROL resume

		$LOGGER "Cardmgr resumed"

	else

		$LOGGER "LID closed"

		$PCMCIA_CONTROL suspend

		$LOGGER "Cardmgr suspended"

		$LOGGER "System Hibernating"

		$HIBERNATE

	fi

}

# some checks at boot time

boot_check ()

{

	if grep -q 'off-line' $AC_STATE; then

		acad_out

	fi

}

# Volume keys

btn_mute ()

{

	/usr/bin/amixer set PCM toggle

}

btn_volup ()

{

	/usr/bin/amixer set PCM 1+

}

btn_voldown ()

{

	/usr/bin/amixer set PCM 1-

}

# ASUS Laptop keys

btn_internet ()

{

	su - dstewen -c "export DISPLAY=:0.0;/usr/bin/epiphany &"

}

btn_email ()

{

	su - dstewen -c "export DISPLAY=:0.0;/usr/bin/evolution &"

}

btn_explorer ()

{

	su - dstewen -c "export DISPLAY=:0.0;/usr/bin/nautilus &"

}

btn_wireless ()

# Fn + F2 button 

{

	PCMCIA_CARD=$(gawk -F'"' '/PRODID_2/ { print $2 }' <($PCMCIA_CONTROL info))

	PCMCIA_CARD_STATUS=$(gawk -F':' '/function 0/ { print $2 }' <($PCMCIA_CONTROL status))

	if (PCMCIA_CARD='ISL3890' && PCMCIA_CARD_STATUS=' [ready]'); then

                $PCMCIA_CONTROL eject

		$LOGGER "Wireless OFF. Ready to eject pcmcia card."

	else

		$LOGGER "ISL3890 not installed. Cannot turn off wireless"

	fi

}

btn_LCD_off ()

{

	$LOGGER "LCD turned off"

}

btn_LCD_on ()

{

	$LOGGER "LCD turned on"

}

# Let's see which event occured and what action to take :-)

# Have a look at /var/log/acpid to see what your events look like

# and adjust accordingly

case "$*" in

	ac_adapter\ AC\ 00000080\ 00000000)

		acad_out;;

	ac_adapter\ AC\ 00000080\ 00000001)

		acad_in;;

	battery\ BAT0\ 00000080\ ????????)

		battery;;

	button?lid\ LID\ 00000080\ ????????)

	# the last eight digits count the times the lid was shut

		btn_lid;;

	button?power\ PWRF\ 00000080\ ????????)

	# the last eight digits count the times the button was pressed

		btn_pwr;;

	button?sleep\ SLPB\ 00000080\ ????????)

		btn_sleep;;

	boot_check)

	# to perform some checks at boot time

		boot_check;;

	#Hotkeys

	hotkey\ HOTK\ 00000032\ ????????)

		btn_mute;;

	hotkey\ HOTK\ 00000030\ ????????)

		btn_volup;;

	hotkey\ HOTK\ 00000031\ ????????)

		btn_voldown;;

	hotkey\ HOTK\ 00000033\ ????????)

		btn_LCD_on;;

	hotkey\ HOTK\ 00000034\ ????????)

		btn_LCD_off;;

	hotkey\ HOTK\ 00000052\ ????????)

		btn_explorer;;

	hotkey\ HOTK\ 00000051\ ????????)

		btn_internet;;

	hotkey\ HOTK\ 00000050\ ????????)

		btn_email;;

	hotkey\ HOTK\ 0000005d\ ????????)

		btn_wireless;;

	*)

		no_action;;

esac

----------------------------------------------------

Here is my /etc/hibernate/hibernate.conf

----------------------------------------------------

# Example hibernate.conf file. Adapt to your own tastes.

# Options are not case sensitive.

# 

# Run "hibernate -h" for help on the configuration items.

### swsusp2_15 (for Software Suspend 2)

UseSwsusp2 yes

Reboot no

EnableEscape yes

DefaultConsoleLevel 1

# ImageSizeLimit 200

## useful for initrd usage:

SuspendDevice /dev/hda8

# LoadSuspendModules suspend_swap suspend_lzf suspend_text

# UnloadSuspendModulesAfterResume yes

### sysfs_power_state

## To use /sys/power/state to suspend your machine (which may offer

## suspend-to-RAM, suspend-to-disk, standby, etc) comment out all the options

## above for Software Suspend 2, and uncomment this line. You may replace mem

## with any one of the states from "cat /sys/power/state"

# UseSysfsPowerState mem

### global settings

Verbosity 3

LogFile /var/log/hibernate.log

LogVerbosity 3

# AlwaysForce yes

AlwaysKill yes

# SwsuspVT 15

Distribution gentoo (not required - autodetection should work)

### bootsplash

## If you use bootsplash, also enabling LeaveXBeforeSuspend is recommended if

## you use X, otherwise you may end up with a garbled X display.

Bootsplash on

BootsplashConfig /etc/splash/default/1024x768.cfg

### clock

SaveClock yes

### devices

IncompatibleDevices /dev/dsp /dev/ttySL0

### diskcache

DisableWriteCacheOn /dev/hda

### filesystems

Unmount /mnt/xp /mnt/ntfs/data /mnt/ntfs/prog /mnt/usb /mnt/smb/Storage

# Mount /windows

### grub

# ChangeGrubMenu yes

# GrubMenuFile /boot/grub/menu.lst

# AlternateGrubMenuFile /boot/grub/menu-suspended.lst

### lilo

# EnsureLILOResumes yes

### lock (generally you only want one of the following options)

# LockKDE yes

LockXScreenSaver yes

#LockConsoleAs root

### misclaunch

# OnSuspend 20 echo "Good night!"

# OnResume 20 echo "Good morning!"

### modules

# UnloadModules snd_via82cxxx usb-ohci

UnloadAllModules yes

UnloadBlacklistedModules yes

LoadModules auto

# LoadModulesFromFile /etc/modules

### modules-gentoo

GentooModulesAutoload yes

### network

DownInterfaces eth0

# UpInterfaces auto

### programs

IncompatiblePrograms xmms

### services

# RestartServices postfix

# StopServices alsasound

# StartServices aumix

### xhacks

LeaveXBeforeSuspend yes

# nVidiaHack yes

--------------------------------------------------

----------

