op_cpuspeed: show current clock
[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 [ "$curmhz" -gt "$maxmhz" ]; then
12   curmhz=$maxmhz
13 fi
14
15 if [ "$1" = "-n" ]; then
16     shift
17     warn=no
18 fi
19
20 if [ ! -e $device ]; then
21     if [ -z "$1" -a -n "$DISPLAY" ]; then
22         zenity --info --title="CPU-Settings not supported" --text \
23             "Sorry, the experimental kernel does not support setting the clockspeed (yet)."
24     fi
25     exit 1
26 fi
27
28 if [ ! $1 ]; then
29         if [ $DISPLAY ]; then
30                 newmhz=$(zenity --scale --text "Set CPU clockspeed" --min-value=$minmhz --max-value=$maxmhz --value=$curmhz --step 1)
31         else
32                 read -p "Please enter the desired clockspeed: " newmhz
33         fi
34 else
35         newmhz=$1
36 fi
37
38 if ! [ 0 -lt "$newmhz" -a "$newmhz" -lt 10000 ]; then
39         echo "invalid argument: $newmhz"
40         exit 1
41 fi
42
43 if [ $newmhz ]; then
44         if [ $newmhz -gt $safemhz ]; then
45                 if [ $warn != no ]; then 
46                         if [ $DISPLAY ]; then
47                                 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 $?)
48                                 echo $answer
49                                 if [ $answer = 1 ]; then exit 1; fi
50                         else
51                                 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
52                                 echo $answer
53                                 if [ $answer = n ]; then exit 1; fi
54                         fi
55                 fi
56         fi
57  
58         if [ $newmhz -le $minmhz ]; then newmhz=$minmhz; fi
59         if [ $newmhz -ge $maxmhz ]; then newmhz=$maxmhz; fi
60         echo $newmhz > $device
61         echo "cpu_mhz_max set to $(cat $device)"
62
63         if [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
64                 # must poke cpufreq so it does the actual clock transition
65                 # according to new limits
66                 gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
67                 echo $gov > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
68                 if [ "$gov" = "userspace" ]; then
69                         echo $[ $newmhz * 1000 ] > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
70                 fi
71                 echo "current CPU clock is $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)"
72         fi
73 fi