3 . /usr/pandora/scripts/op_paths.sh
5 # XXX: better use lockfile (or something), but it's not in current firmware
6 test -e /tmp/op_power.lock && exit 2
7 touch /tmp/op_power.lock
10 return 1 # 0 when debugging, 1 when not
13 test -e $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig && lidconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig) # read lid conf. file if it exists
15 #powerbuttonconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.powerbuttonconfig)
17 if [ -e /tmp/powerstate ]; then
18 powerstate="$(cat /tmp/powerstate)"
23 debug && echo "powerstate=$powerstate"
26 hcistate=$(hciconfig hci0 | grep DOWN)
27 if [ $hcistate ]; then
28 echo "down" > /tmp/hcistate
30 echo "up" > /tmp/hcistate
33 wlstate=$(lsmod | grep -m1 wl1251)
34 if [ -z "$wlstate" ]; then
35 echo "down" > /tmp/wlstate
37 echo "up" > /tmp/wlstate
39 rmmod board_omap3pandora_wifi 2> /dev/null
40 rmmod wl1251_sdio wl1251
45 hcistate=$(cat /tmp/hcistate)
46 if [ "$hcistate" = "up" ]; then
47 hciconfig hci0 up pscan
49 wlstate=$(cat /tmp/wlstate)
50 if [ "$wlstate" = "up" ]; then
51 /etc/init.d/wl1251-init start
53 rm -f /tmp/hcistate /tmp/wlstate
57 echo 0 > /sys/class/graphics/fb0/blank
59 maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
61 if [ -f /tmp/oldbright ]; then
62 oldbright=$(cat /tmp/oldbright)
64 if [ $oldbright -eq 0 ]; then
65 oldbright=$(cat /etc/pandora/conf/brightness.state)
67 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
68 /usr/pandora/scripts/op_bright.sh $oldbright
70 /usr/pandora/scripts/op_bright.sh $maxbright
75 brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
76 if [ $brightness -gt 0 ]; then
77 echo $brightness > /tmp/oldbright
79 echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
81 echo 1 > /sys/class/graphics/fb0/blank
84 lowPowerOn(){ #switch from normal to lowpower mode
87 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
95 cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
96 /usr/pandora/scripts/op_cpuspeed.sh 125
99 lowPowerOff(){ # switch from lowpower to normal mode
100 oldspeed=$(cat /tmp/oldspeed)
101 /usr/pandora/scripts/op_cpuspeed.sh $oldspeed
106 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
111 echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
115 # TODO: check if desktop is visible; maybe use layer3?
116 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
117 cmd="DISPLAY=:0.0 zenity --info --text \"$1\""
118 su -c "$cmd" $xfceuser
124 if ! [ -e /sys/power/state ]; then
125 # no kernel suspend support
129 # can't suspend while SGX is in use due to bugs
130 # (prevents low power states and potential lockup)
131 if lsof -t /dev/pvrsrvkm > /dev/null; then
135 # TODO: we probably want to NOT do real suspend if:
136 # - cards don't unmount (running PNDs will break)
137 # - while charging too, since it stops on suspend?
139 if ! grep -q 'mmc_core.removable=0' /proc/cmdline; then
140 # must unmount cards because they will be "ejected" on suspend
141 # (some filesystems may even deadlock if we don't do this due to bugs)
142 mounts="$(grep "/dev/mmcblk" /proc/mounts | awk '{print $1}' | xargs echo)"
143 for mnt in $mounts; do
144 if ! umount $mnt; then
145 show_message "Could not unmount $mnt, using partial suspend only"
149 swaps="$(grep "/dev/mmcblk" /proc/swaps | awk '{print $1}' | xargs echo)"
150 for swp in $swaps; do
151 if ! swapoff $swp; then
152 show_message "Could not unmount $swp, using partial suspend only"
157 if [ ! -e /etc/pandora/suspend-warned ]; then
158 show_message "Pandora will now suspend.\n\n\
159 Please do not remove SD cards while pandora is suspended, doing so will corrupt them."
160 touch /etc/pandora/suspend-warned
164 # FIXME: fix the kernel and get rid of this
167 # get rid of modules that prevent suspend due to bugs
168 modules="$(lsmod | awk '{print $1}' | xargs echo)"
169 blacklist="ehci_hcd g_zero g_audio g_ether g_serial g_midi gadgetfs g_file_storage
170 g_mass_storage g_printer g_cdc g_multi g_hid g_dbgp g_nokia g_webcam g_ncm g_acm_ms"
172 for mod in $modules; do
173 if echo $blacklist | grep -q "\<$mod\>"; then
174 restore_list="$restore_list $mod"
182 echo mem > /sys/power/state
184 # if we are here, either we already resumed or the suspend failed
185 if [ -n "$restore_list" ]; then
186 modprobe $restore_list
191 echo 255 > /sys/class/leds/pandora\:\:power/brightness
193 # wait here a bit to prevent this script from running again (keep op_power.lock)
194 # in case user did resume using the power switch.
202 echo 16 > /sys/class/leds/pandora\:\:power/brightness
204 if suspend_real; then
213 if [ "$powerstate" = "on" ]; then
215 echo "resume called unexpectedly" >&2
221 shutdown(){ # warns the user and shuts the pandora down
222 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
225 for i in $(seq $time); do
226 precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
228 echo "# Shutdown in $(($time-$i))"
232 countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
233 if [ $? -eq 0 ]; then
234 /sbin/shutdown -h now
236 su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser
240 if [[ "$2" == "" ]]; then
241 if [[ "$1" -le 2 ]]; then # power button was pressed 1-2sec, "suspend"
242 if [[ "$powerstate" == "buttonlowpower" ]]; then
243 (debug && echo "resume") || resume
245 elif [[ "$powerstate" == "on" ]]; then
246 powerstate="buttonlowpower"
247 (debug && echo "suspend") || suspend_
248 elif [[ "$powerstate" == "liddisplayoff" ]]; then
249 powerstate="buttonlowpower"
250 (debug && echo "suspend") || suspend_
252 elif [[ "$1" -ge 3 ]]; then # power button was pressed 3 sec or longer, shutdown
253 if [[ "$powerstate" == "on" ]]; then
254 (debug && echo "shutdown") || shutdown
257 elif [[ "$2" == "lid" ]]; then
258 if [[ "$1" == 0 ]]; then # lid was opened
259 if [[ "$powerstate" == lid* ]]; then
262 (debug && echo "resume") || resume
266 (debug && echo "display_on") || display_on
271 elif [[ "$1" == 1 ]]; then # lid was closed
272 if [[ "$powerstate" == "on" ]]; then
275 (debug && echo "shutdown") || shutdown
278 powerstate="lidlowpower"
279 (debug && echo "suspend") || suspend_
282 (debug && echo "display_off") || display_off
283 powerstate="liddisplayoff"
289 debug && echo "powerstate=$powerstate"
290 echo "$powerstate" > /tmp/powerstate
292 rm -f /tmp/op_power.lock