From: Grazvydas Ignotas Date: Tue, 14 Feb 2012 23:48:14 +0000 (+0200) Subject: op_power.sh: restructure, reduce dupe code X-Git-Tag: sz_beta3~39 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=openpandora.oe.git;a=commitdiff_plain;h=63406289236b94f2123c40b5ab5346da42926f6b op_power.sh: restructure, reduce dupe code avoid SGX suspend too when it's running --- diff --git a/recipes/pandora-system/pandora-scripts.bb b/recipes/pandora-system/pandora-scripts.bb index 7950267..fda4b53 100644 --- a/recipes/pandora-system/pandora-scripts.bb +++ b/recipes/pandora-system/pandora-scripts.bb @@ -6,7 +6,7 @@ COMPATIBLE_MACHINE = "omap3-pandora" DEPENDS = "zenity dbus" RDEPENDS = "zenity dbus" -PR = "r80" +PR = "r81" SRC_URI = " \ file://op_paths.sh \ diff --git a/recipes/pandora-system/pandora-scripts/op_power.sh b/recipes/pandora-system/pandora-scripts/op_power.sh index dd0101d..5cee08c 100644 --- a/recipes/pandora-system/pandora-scripts/op_power.sh +++ b/recipes/pandora-system/pandora-scripts/op_power.sh @@ -53,38 +53,58 @@ resume_net() { rm -f /tmp/hcistate /tmp/wlstate } +display_on() { + echo 0 > /sys/class/graphics/fb0/blank + + maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness) + oldbright=0 + if [ -f /tmp/oldbright ]; then + oldbright=$(cat /tmp/oldbright) + fi + if [ $oldbright -eq 0 ]; then + oldbright=$(cat /etc/pandora/conf/brightness.state) + fi + if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then + /usr/pandora/scripts/op_bright.sh $oldbright + else + /usr/pandora/scripts/op_bright.sh $maxbright + fi +} + +display_off() { + brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS) + if [ $brightness -gt 0 ]; then + echo $brightness > /tmp/oldbright + fi + echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS + + echo 1 > /sys/class/graphics/fb0/blank +} + lowPowerOn(){ #switch from normal to lowpower mode - cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed - cat $SYSFS_BACKLIGHT_BRIGHTNESS > /tmp/oldbright + display_off + pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p') for PID in $pidlist do - kill -19 $PID #send SIGSTOP + kill -STOP $PID done + suspend_net - echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS - echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank /usr/pandora/scripts/op_cpuspeed.sh 125 } lowPowerOff(){ # switch from lowpower to normal mode oldspeed=$(cat /tmp/oldspeed) /usr/pandora/scripts/op_cpuspeed.sh $oldspeed - oldbright=$(cat /tmp/oldbright) - maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness) - echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank - sleep 0.1s # looks cleaner, could flicker without - oldspeed=$(cat /tmp/oldspeed) - if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then - /usr/pandora/scripts/op_bright.sh $oldbright - else - /usr/pandora/scripts/op_bright.sh $maxbright - fi + + display_on resume_net + pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p') for PID in $pidlist do - kill -18 $PID #send SIGCONT + kill -CONT $PID done echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright } @@ -92,6 +112,21 @@ lowPowerOff(){ # switch from lowpower to normal mode suspend_real() { delay=0 + if ! [ -e /sys/power/state ]; then + # no kernel suspend support + return 1 + fi + + # can't suspend while SGX is in use due to bugs + # (prevents low power states and potential lockup) + if lsof -t /dev/pvrsrvkm > /dev/null; then + return 1 + fi + + # TODO: we probably want to NOT do real suspend if: + # - cards don't unmount (running PNDs will break) + # - while charging too, since it stops on suspend? + # FIXME: fix the kernel and get rid of this suspend_net @@ -126,21 +161,24 @@ suspend_real() { # wait here a bit to prevent this script from running again (keep op_power.lock) # in case user did resume using the power switch. sleep 2 + + return 0 } suspend_() { # dim power LED echo 16 > /sys/class/leds/pandora\:\:power/brightness - if [ -e /sys/power/state ]; then - suspend_real + if suspend_real; then + # resumed already + powerstate="on" else lowPowerOn fi } resume() { - if [ -e /sys/power/state ]; then + if [ "$powerstate" = "on" ]; then # nothing to do echo "resume called unexpectedly" >&2 else @@ -148,13 +186,6 @@ resume() { fi } -suspend_check() { - if [ -e /sys/power/state ]; then - # in case of real suspend we've already resumed - powerstate="on" - fi -} - shutdown(){ # warns the user and shuts the pandora down xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}') time=5 @@ -174,42 +205,14 @@ shutdown(){ # warns the user and shuts the pandora down fi } -displayOn(){ # turns the display on - #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank - #sleep 0.1s # looks cleaner, could flicker without - maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness) - oldbright=0 - if [ -f /tmp/oldbright ]; then - oldbright=$(cat /tmp/oldbright) - fi - if [ $oldbright -eq 0 ]; then - oldbright=$(cat /etc/pandora/conf/brightness.state) - fi - if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then - /usr/pandora/scripts/op_bright.sh $oldbright - else - /usr/pandora/scripts/op_bright.sh $maxbright - fi -} - -displayOff(){ # turns the display off - brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS) - if [ $brightness -gt 0 ]; then - echo $brightness > /tmp/oldbright - fi - echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS - #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank -} - if [[ "$2" == "" ]]; then if [[ "$1" -le 2 ]]; then # power button was pressed 1-2sec, "suspend" if [[ "$powerstate" == "buttonlowpower" ]]; then (debug && echo "resume") || resume powerstate="on" elif [[ "$powerstate" == "on" ]]; then - (debug && echo "suspend") || suspend_ powerstate="buttonlowpower" - suspend_check + (debug && echo "suspend") || suspend_ fi elif [[ "$1" -ge 3 ]]; then # power button was pressed 3 sec or longer, shutdown if [[ "$powerstate" == "on" ]]; then @@ -225,7 +228,7 @@ elif [[ "$2" == "lid" ]]; then powerstate="on" ;; *) - (debug && echo "displayOn") || displayOn + (debug && echo "display_on") || display_on powerstate="on" ;; esac @@ -237,12 +240,11 @@ elif [[ "$2" == "lid" ]]; then (debug && echo "shutdown") || shutdown ;; "lowpower") - (debug && echo "suspend") || suspend_ powerstate="lidlowpower" - suspend_check + (debug && echo "suspend") || suspend_ ;; *) - (debug && echo "displayOff") || displayOff + (debug && echo "display_off") || display_off powerstate="liddisplayoff" ;; esac