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