op_cpuspeed.sh: update userspace governor (if it's set)
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_cpuspeed.sh
1 #!/bin/bash
2 #get value range
3 minmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'min:' | awk -F\: '{print $2}')"
4 safemhz="$(cat /etc/pandora/conf/cpu.conf | grep 'safe:' | awk -F\: '{print $2}')"
5 maxmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'max:' | awk -F\: '{print $2}')"
6 warn="$(cat /etc/pandora/conf/cpu.conf | grep 'warn:' | awk -F\: '{print $2}')"
7 device=/proc/pandora/cpu_mhz_max
8 curmhz="$(cat $device)"
9 newmhz="$(cat $device)"
10
11 if [ "$1" = "-n" ]; then
12     shift
13     warn=no
14 fi
15
16 if [ ! -e $device ]; then
17     if [ -z "$1" -a -n "$DISPLAY" ]; then
18         zenity --info --title="CPU-Settings not supported" --text \
19             "Sorry, the experimental kernel does not support setting the clockspeed (yet)."
20     fi
21     exit 1
22 fi
23
24 if [ ! $1 ]; then
25         if [ $DISPLAY ]; then
26                 newmhz=$(zenity --scale --text "Set CPU clockspeed" --min-value=$minmhz --max-value=$maxmhz --value=$curmhz --step 1)
27         else
28                 read -p "Please enter the desired clockspeed: " newmhz
29         fi
30 else
31         newmhz=$1
32 fi
33
34 if ! [ 0 -lt "$newmhz" -a "$newmhz" -lt 10000 ]; then
35         echo "invalid argument: $newmhz"
36         exit 1
37 fi
38
39 if [ $newmhz ]; then
40         if [ $newmhz -gt $safemhz ]; then
41                 if [ $warn != no ]; then 
42                         if [ $DISPLAY ]; then
43                                 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 $?)
44                                 echo $answer
45                                 if [ $answer = 1 ]; then exit 1; fi
46                         else
47                                 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
48                                 echo $answer
49                                 if [ $answer = n ]; then exit 1; fi
50                         fi
51                 fi
52         fi
53  
54         if [ $newmhz -le $minmhz ]; then newmhz=$minmhz; fi
55         if [ $newmhz -ge $maxmhz ]; then newmhz=$maxmhz; fi
56         echo $newmhz > $device
57         echo cpu_mhz_max set to $(cat $device)
58
59         if [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
60                 # must poke cpufreq so it does the actual clock transition
61                 # according to new limits
62                 gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
63                 echo $gov > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
64                 if [ "$gov" = "userspace" ]; then
65                         echo $[ $newmhz * 1000 ] > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
66                 fi
67         fi
68 fi