op_cpuspeed.sh: If current speed is higher than allowed max speed, set current speed...
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_cpuspeed.sh
old mode 100644 (file)
new mode 100755 (executable)
index df9b72a..beb1b7e
@@ -1,34 +1,72 @@
 #!/bin/bash
 #get value range
-minmhz=14
-safemhz=600
-maxmhz=900
-curmhz=$(cat /proc/pandora/cpu_mhz_max)
+minmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'min:' | awk -F\: '{print $2}')"
+safemhz="$(cat /etc/pandora/conf/cpu.conf | grep 'safe:' | awk -F\: '{print $2}')"
+maxmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'max:' | awk -F\: '{print $2}')"
+warn="$(cat /etc/pandora/conf/cpu.conf | grep 'warn:' | awk -F\: '{print $2}')"
 device=/proc/pandora/cpu_mhz_max
+curmhz="$(cat $device)"
+newmhz="$(cat $device)"
+
+if [ "$curmhz" -gt "$maxmhz" ]; then
+  curmhz=$maxmhz
+fi
+
+if [ "$1" = "-n" ]; then
+    shift
+    warn=no
+fi
+
+if [ ! -e $device ]; then
+    if [ -z "$1" -a -n "$DISPLAY" ]; then
+        zenity --info --title="CPU-Settings not supported" --text \
+            "Sorry, the experimental kernel does not support setting the clockspeed (yet)."
+    fi
+    exit 1
+fi
+
 if [ ! $1 ]; then
        if [ $DISPLAY ]; then
-               newmhz=$(zenity --scale --text "set cpu mhz" --min-value=$minmhz --max-value=$maxmhz --value=$curmhz --step 1)
+               newmhz=$(zenity --scale --text "Set CPU clockspeed" --min-value=$minmhz --max-value=$maxmhz --value=$curmhz --step 1)
        else
-               newmhz=$(read -p "Pleas enter the desired speed")
+               read -p "Please enter the desired clockspeed: " newmhz
        fi
 else
-newmhz=$1
+       newmhz=$1
 fi
+
+if ! [ 0 -lt "$newmhz" -a "$newmhz" -lt 10000 ]; then
+       echo "invalid argument: $newmhz"
+       exit 1
+fi
+
 if [ $newmhz ]; then
-        if [ $newmhz -ge $safemhz ]; then
-                if [ $DISPLAY ]; then
-                        answer=$(zenity --question --title "Alert" --text "You are trying to set the cpu clock to $newmhz which is above its specification of $safemhz, doing so may burn down your house, sour milk, or just blow up (ok, not that likely)! proceed?";echo $?)
-                        echo $answer
-                        if [ $answer = 1 ]; then exit 1; fi
-                else
-                       answer="n";read -p "You are trying to set the cpu clock to $newmhz which is above its specification of $safemhz, doing so may burn down your house, sour milk, or just blow up (ok, not that likely)! proceed? [y/n]" -t 10 answer
-                       echo $answer
-                       if [ $answer = n ]; then exit 1; fi
-                fi
+        if [ $newmhz -gt $safemhz ]; then
+               if [ $warn != no ]; then 
+                       if [ $DISPLAY ]; then
+                               answer=$(zenity --question --title "Alert" --text "You are trying to set the CPU clock to $newmhz which is above the warning level of $safemhz, doing so may burn down your house, sour milk, or just blow up (OK, not that likely)! Proceed?";echo $?)
+                               echo $answer
+                               if [ $answer = 1 ]; then exit 1; fi
+                       else
+                               answer="n";read -p "You are trying to set the CPU clock to $newmhz which is above the warning level of $safemhz, doing so may burn down your house, sour milk, or just blow up (OK, not that likely)! Proceed? [y/n]" -t 10 answer
+                               echo $answer
+                               if [ $answer = n ]; then exit 1; fi
+                       fi
+               fi
         fi
  
         if [ $newmhz -le $minmhz ]; then newmhz=$minmhz; fi
         if [ $newmhz -ge $maxmhz ]; then newmhz=$maxmhz; fi
        echo $newmhz > $device
-       echo cpu_mhz_max set to $(cat /proc/pandora/cpu_mhz_max)
+       echo cpu_mhz_max set to $(cat $device)
+
+       if [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
+               # must poke cpufreq so it does the actual clock transition
+               # according to new limits
+               gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
+               echo $gov > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+               if [ "$gov" = "userspace" ]; then
+                       echo $[ $newmhz * 1000 ] > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
+               fi
+       fi
 fi