diff options
author | Michael Biebl <mbiebl@gmail.com> | 2008-03-07 08:23:19 +0100 |
---|---|---|
committer | Michael Biebl <mbiebl@gmail.com> | 2008-03-07 08:23:19 +0100 |
commit | acaf13ae802f72a3c37217c86f80c80db69f852e (patch) | |
tree | 48781fd4b4994529e7374e47b124e52c9ae4e25b /pm | |
parent | ae82bec26a64721674148cfa15a1f204528de2c2 (diff) | |
parent | a0c3dfab5a1381677b2ef991ae40c7e7b52c1c60 (diff) |
Merge branch 'master' of git://anongit.freedesktop.org/git/pm-utils
Diffstat (limited to 'pm')
-rw-r--r-- | pm/HOWTO.hooks | 7 | ||||
-rw-r--r-- | pm/functions.in | 31 | ||||
-rwxr-xr-x | pm/sleep.d/20video | 67 | ||||
-rwxr-xr-x | pm/sleep.d/94cpufreq | 15 | ||||
-rwxr-xr-x | pm/sleep.d/99video | 110 | ||||
-rw-r--r-- | pm/sleep.d/Makefile.am | 1 |
6 files changed, 122 insertions, 109 deletions
diff --git a/pm/HOWTO.hooks b/pm/HOWTO.hooks index 43fe40d..0ce10de 100644 --- a/pm/HOWTO.hooks +++ b/pm/HOWTO.hooks @@ -6,12 +6,19 @@ A pm-utils hook is simply an executable file that accepts a single parameter. For hooks in sleep.d, the potential values of that parameter are: suspend -- The hook MUST perform whatever action is appropriate when the system is preparing for S3 sleep (or its equivalent). +suspend_hybrid -- The hook MUST perform whatever action is appropriate + when entering suspend mode. The hook SHOULD also save + any state it may need to bring the system back from + hibernate mode. resume -- The hook MUST perform whatever action is appropriate when the system is coming out of suspend. hibernate -- The hook MUST perform whatever action is appropriate when the system is preparing for suspend-to-disk. thaw -- The hook MUST perform whatever action is appropriate when the system is coming out of suspend-to-disk. +help -- If your hook parses the PM_CMDLINE environment variable for switches, + this function SHOULD output text describing the parameters it parses + in a format easily understandable by an end-user. For hooks in power.d, the potential values of that parameter are: true -- the hook MUST perform whatever action is appropriate when the system diff --git a/pm/functions.in b/pm/functions.in index e0fc960..dbce365 100644 --- a/pm/functions.in +++ b/pm/functions.in @@ -34,6 +34,8 @@ export LC_COLLATE=C set +a +log() { [ $LOGGING ] && echo $*; } + source_configs() { for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do @@ -48,7 +50,7 @@ source_configs SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}" [ -f "${SLEEP_FUNCTIONS}" ] || { - echo "Requested sleep module $SLEEP_MODULE not available." + log "Requested sleep module $SLEEP_MODULE not available." exit 1 } @@ -121,9 +123,9 @@ command_exists() hook_exit_status(){ case $1 in - 0) echo "success." ;; - $NA) echo "not applicable." ;; - *) echo "Returned exit code $1." ;; + 0) log "success." ;; + $NA) log "not applicable." ;; + *) log "Returned exit code $1." ;; esac } @@ -153,7 +155,7 @@ run_hooks() { fi [ -x "${hook}" ] && ( IFS="${oifs}" - echo "$(date): running ${hook} $2" + log "$(date): running ${hook} $2" "${hook}" $2 hook_exit_status $? ) @@ -192,6 +194,7 @@ init_logfile() echo "Please pass a filename to init_logfile." return 1 fi + export LOGGING="true" exec > "$1" 2>&1 } @@ -201,7 +204,7 @@ _rmmod() touch "${STORAGEDIR}/module:$1" return 0 else - echo "# could not unload '$1', usage count was $2" + log "# could not unload '$1', usage count was $2" return 1 fi } @@ -257,7 +260,7 @@ if ! command_exists service; then shift "/etc/init.d/$svc" "$@" else - echo "$1" $": unrecognized service" 1>&2 + log "$1" $": unrecognized service" 1>&2 return 1 fi } @@ -278,10 +281,20 @@ restartservice() savestate() { - echo "$2" > "${STORAGEDIR}/state:$1" + if [ -n "$2" ]; then + echo "$2" > "${STORAGEDIR}/state:$1" + else + cat > "${STORAGEDIR}/state:$1" + fi } +state_exists() +{ + [ -O "${STORAGEDIR}/state:$1" ] +} + + restorestate() { - [ -O "${STORAGEDIR}/state:${1}" ] && cat "${STORAGEDIR}/state:${1}" + state_exists "$1" && cat "${STORAGEDIR}/state:$1" } diff --git a/pm/sleep.d/20video b/pm/sleep.d/20video deleted file mode 100755 index 668b519..0000000 --- a/pm/sleep.d/20video +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh -# -# Copyright 2006-2007 Richard Hughes <richard@hughsie.com> -# Copyright 2007 Peter Jones <pjones@redhat.com> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of version 2 of the GNU General Public License as -# published by the Free Software Foundation. - -. "${PM_FUNCTIONS}" - -if command_exists vbetool; then - vbe() { vbetool "$@"; } -else - vbe() { echo "vbetool not found" 1>&2; return 1; } -fi - -if command_exists radeontool; then - radeon() { radeontool "$@"; } -else - radeon() { echo "radeontool not found" 1>&2; return 1; } -fi - -suspend_video() -{ - # 0=nothing, 1=s3_bios, 2=s3_mode, 3=both - if [ "${DISPLAY_QUIRK_S3_BIOS}" = "true" -a \ - "${DISPLAY_QUIRK_S3_MODE}" = "true" ]; then - sysctl -w kernel.acpi_video_flags=3 - elif [ "${DISPLAY_QUIRK_S3_BIOS}" = "true" ]; then - sysctl -w kernel.acpi_video_flags=1 - elif [ "${DISPLAY_QUIRK_S3_MODE}" = "true" ]; then - sysctl -w kernel.acpi_video_flags=2 - else - sysctl -w kernel.acpi_video_flags=0 - fi - - # We might need to do one or many of these quirks - if [ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ]; then - radeon dac off - radeon light off - fi - if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ]; then - vbe vbestate save > /var/run/vbestate - fi - if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ]; then - vbe vbemode get > /var/run/vbemode - fi - if [ "${DISPLAY_QUIRK_VGA_MODE_3}" = "true" ]; then - vbe vbemode set 3 - fi - if [ "${DISPLAY_QUIRK_DPMS_SUSPEND}" = "true" ]; then - vbe dpms suspend - fi -} - - -case "$1" in - suspend*) - suspend_video - ;; - hibernate) - if [ "$HIBERNATE_RESUME_POST_VIDEO" = "yes" ]; then - suspend_video - fi - ;; -esac diff --git a/pm/sleep.d/94cpufreq b/pm/sleep.d/94cpufreq index 9157fb4..cfb0c60 100755 --- a/pm/sleep.d/94cpufreq +++ b/pm/sleep.d/94cpufreq @@ -7,12 +7,17 @@ hibernate_cpufreq() { ( cd /sys/devices/system/cpu/ - for x in cpu[0-9]*/cpufreq/scaling_governor ; do - [ -f "$x" ] || continue + for x in cpu[0-9]*; do + # if cpufreq is a symlink, it is handled by another cpu. Skip. + [ -L "$x/cpufreq" ] && continue + gov="$x/cpufreq/scaling_governor" + # if we do not have a scaling_governor file, skip. + [ -f "$gov" ] || continue + # if our temporary governor is not available, skip. grep -q "$TEMPORARY_CPUFREQ_GOVERNOR" \ - "${x%/*}/scaling_available_governors" || continue - savestate "${x%%/*}_governor" $(cat "$x") - echo "$TEMPORARY_CPUFREQ_GOVERNOR" > "$x" + "$x/cpufreq/scaling_available_governors" || continue + savestate "${x}_governor" $(cat "$gov") + echo "$TEMPORARY_CPUFREQ_GOVERNOR" > "$gov" done ) } diff --git a/pm/sleep.d/99video b/pm/sleep.d/99video index cdf2bc8..1dc88bd 100755 --- a/pm/sleep.d/99video +++ b/pm/sleep.d/99video @@ -9,6 +9,26 @@ . "${PM_FUNCTIONS}" +for opt in $PM_CMDLINE; do + [ "${opt#--quirk-}" = "$opt" ] && continue # not one we care about. + case "${1##--quirk-}" in # just quirks, please + dpms-on) QUIRK_DPMS_ON="true" ;; + dpms-suspend) QUIRK_DPMS_SUSPEND="true" ;; + radeon-off) QUIRK_RADEON_OFF="true" ;; + reset-brightness) QUIRK_RESET_BRIGHTNESS="true" ;; + s3-bios) QUIRK_S3_BIOS="true" ;; + s3-mode) QUIRK_S3_MODE="true" ;; + vbe-post) QUIRK_VBE_POST="true" ;; + vbemode-restore) QUIRK_VBEMODE_RESTORE="true" ;; + vbestate-restore) QUIRK_VBESTATE_RESTORE="true" ;; + vga-mode3) QUIRK_VGA_MODE_3="true" ;; + none) QUIRK_NONE="true" ;; + *) continue ;; + esac + shift +done + + reset_brightness() { for bl in /sys/class/backlight/* ; do @@ -49,44 +69,80 @@ resume_fbcon() done } +# Some tiny helper functions for quirk handling +quirk() { [ "$1" = "true" ] && [ -z $QUIRK_NONE ]; } + +# save/restore vbe state +vbe_savestate() { vbe vbestate save |savestate vbestate; } +vbe_restorestate() { restorestate vbestate |vbe vbestate restore; } + +# save/restore the vbe mode +vbe_savemode() { vbe vbemode get |savestate vbemode; } +vbe_restoremode() { vbe vbemode get |savestate vbemode; } + +# post the video card +vbe_post() { vbe post; sleep 0.1; } + +# turn critical bits of radeon cards off/on +radeon_off() { radeon dac off; radeon light off; } +radeon_on() { radeon dac on; radeon light on; } + +suspend_video() +{ + # 0=nothing, 1=s3_bios, 2=s3_mode, 3=both + local acpi_flag=0 + [ "${QUIRK_S3_BIOS}" = "true" ] && acpi_flag=$(($acpi_flag + 1)) + [ "${QUIRK_S3_MODE}" = "true" ] && acpi_flag=$(($acpi_flag + 2)) + sysctl -w kernel.acpi_video_flags=$acpi_flag + + quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_savestate + quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_savemode + quirk "${QUIRK_RADEON_OFF}" && radeon_off + quirk "${QUIRK_VGA_MODE_3}" && vbe vbemode set 3 + quirk "${QUIRK_DPMS_SUSPEND}" && vbe dpms suspend + save_fbcon # there should be a quirk, but HAL does not pass it. +} resume_video() { - if [ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ]; then - radeon dac on - radeon light on - fi # We might need to do one or many of these quirks - if [ "${DISPLAY_QUIRK_VBE_POST}" = "true" ]; then - vbe post - sleep 0.1 - fi - if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ]; then - vbe vbestate restore < /var/run/vbestate - fi - if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ]; then - vbe vbemode set "$(cat /var/run/vbemode)" - fi - # based on data from s2ram - resume_fbcon - if [ "${DISPLAY_QUIRK_DPMS_ON}" = "true" ]; then - vbe dpms on - fi - if [ "${DISPLAY_QUIRK_RESET_BRIGHTNESS}" = "true" ]; then - reset_brightness - fi + quirk "${QUIRK_VBE_POST}" && vbe_post + quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_restorestate + quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_restoremode + resume_fbcon # also should be handled by a quirk. + quirk "${QUIRK_RADEON_OFF}" && radeon_on + quirk "${QUIRK_DPMS_ON}" && vbe dpms on + quirk "${QUIRK_RESET_BRIGHTNESS}" && reset_brightness } +help() { + echo # first echo makes it look nicer. + echo "Video quirk handler options:" + echo + echo " --quirk-dpms-on" + echo " --quirk-dpms-suspend" + echo " --quirk-radeon-off" + echo " --quirk-reset-brightness" + echo " --quirk-s3-bios" + echo " --quirk-s3-mode" + echo " --quirk-vbe-post" + echo " --quirk-vbemode-restore" + echo " --quirk-vbestate-restore" + echo " --quirk-vga-mode3" + echo " --quirk-none" +} case "$1" in - suspend*) - save_fbcon - ;; - resume) - resume_video + suspend*) suspend_video ;; + hibernate) + if [ "$HIBERNATE_RESUME_POST_VIDEO" = "yes" ]; then + suspend_video + fi ;; + resume) resume_video ;; thaw) if [ "${HIBERNATE_RESUME_POST_VIDEO}" = "yes" ]; then resume_video fi ;; + help) help ;; esac diff --git a/pm/sleep.d/Makefile.am b/pm/sleep.d/Makefile.am index 256ee0b..7efbc81 100644 --- a/pm/sleep.d/Makefile.am +++ b/pm/sleep.d/Makefile.am @@ -5,7 +5,6 @@ sleep_SCRIPTS = \ 01grub \ 05led \ 10NetworkManager \ - 20video \ 49bluetooth \ 50modules \ 55battery \ |