1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet
AddConfigHandler SysfsPowerStateConfigEnabler
AddOptionHandler SysfsPowerStateOptionHandler
AddConfigHelp "UseSysfsPowerState <state>" "Enables the use of /sys/power/state for suspending the machine (to RAM or disk). This requires a kernel supporting this interface. <state> must be one of the options listed by \`cat /sys/power/state\`, (eg mem, disk, or standby)."
AddConfigHelp "PowerdownMethod <shutdown|platform|firmware> (requires UseSysfsPowerState)" "If using /sys/power/state to suspend your machine to disk, chooses the method by which to do so. Choosing \"shutdown\" will save state in linux, then tell the bios to powerdown (most reliable). Choosing \"platform\" will save state in linux, then tell the bios to powerdown and blink it's \"suspended LED\". Choosing \"firmware\" will tell the bios to save state itself (needs BIOS-specific suspend partition, and has very little to do with swsusp)."
AddShortOption "n"
AddLongOption "no-suspend"
AddOptionHelp "-n, --no-suspend" "Disables actually suspending the system. This is useful for testing the hibernate script itself."
SYSFS_POWER_STATE_FILE=/sys/power/state
SYSFS_POWERDOWN_METHOD_FILE=/sys/power/disk
IsBadPPCKernel() {
# ppc/powerpc prior to 2.6.16.20 oopsed when you try to activate STR this
# way.
[ $1 != "mem" ] && return 1
case `uname -m` in
ppc|ppc64|powerpc)
;;
*)
return 1
;;
esac
ver=`uname -r | sed -e 's/[^0-9.]*//' | awk 'BEGIN{FS="[.]"}{print($1*16777216)+($2*65536)+($3*256)+$4}'`
[ $ver -lt $((0x02061014)) ] && return 1
return 0
}
SysfsPowerStateConfigEnabler() {
[ "$1" != "usesysfspowerstate" ] && return 1
[ -n "$USING_SYSFS_POWER_STATE" ] && return 0
if [ -n "$NO_COMPLAIN_UNSUPPORTED" ] ; then
# Just bail silently if we don't detect it.
if ! test -f $SYSFS_POWER_STATE_FILE || ! grep -q $2 $SYSFS_POWER_STATE_FILE ; then
return 0
fi
IsBadPPCKernel $2 && return 0
fi
UsingSuspendMethod sysfs_power_state
AddConfigHandler SysfsPowerStateConfigOptions
AddSuspendHook 10 EnsureSysfsPowerStateCapable
AddSuspendHook 99 DoSysfsPowerStateSuspend
USING_SYSFS_POWER_STATE=$2
return 0
}
SysfsPowerStateOptionHandler() {
[ -z "$USING_SYSFS_POWER_STATE" ] && return 1
case $1 in
-n|--no-suspend)
SYSFS_POWER_STATE_NO_SUSPEND=1
;;
*)
return 1
esac
return 0
}
SysfsPowerStateConfigOptions() {
case $1 in
powerdownmethod)
SYSFS_POWER_STATE_POWERDOWN_METHOD=$2
;;
*)
return 1
esac
return 0
}
DoSysfsPowerStateSuspend() {
if [ -z "$SYSFS_POWER_STATE_NO_SUSPEND" ] ; then
vecho 1 "$EXE: Activating sysfs power state $USING_SYSFS_POWER_STATE ..."
[ -n "$SYSFS_POWER_STATE_POWERDOWN_METHOD" ] && \
[ -f "$SYSFS_POWERDOWN_METHOD_FILE" ] && \
/bin/echo $SYSFS_POWER_STATE_POWERDOWN_METHOD > $SYSFS_POWERDOWN_METHOD_FILE
/bin/echo -n $USING_SYSFS_POWER_STATE > $SYSFS_POWER_STATE_FILE
else
vecho 1 "$EXE: Not actually suspending (--no-suspend given)"
fi
return 0
}
# EnsureSysfsPowerStateCapable: makes sure we have /sys/power/state and that
# the selection option is one of the available suspend modes.
EnsureSysfsPowerStateCapable() {
if ! test -f $SYSFS_POWER_STATE_FILE ; then
vecho 0 "Your kernel does not have power management built in."
return 2
fi
if ! grep -q $USING_SYSFS_POWER_STATE $SYSFS_POWER_STATE_FILE ; then
vecho 0 "Your kernel or machine does support the power state \"$USING_SYSFS_POWER_STATE\"."
return 2
fi
if IsBadPPCKernel $USING_SYSFS_POWER_STATE ; then
vecho 0 "Suspend-to-RAM can not be activated this way on PowerPC."
vecho 0 "Have a look at pmud or pbbuttonsd."
return 2
fi
return 0
}
# $Id$
|