2 # kernel configuration script for power user kernel
3 # (c) Copyright 2010 by Thomas Tanner <maemo@tannerlab.com>
5 # version 0.3 (16. May 2010)
8 echo "$0 command [options]"
10 echo " show - show current settings"
11 echo " load <file> - load settings from file"
12 echo " save <file> - save settings to file (abs. path or filename in /home/user/.kernel)"
13 echo " default [<file>] - set file or the current settings as default settings"
14 echo " limits min max - set the frequency limits ('-' keeps the current setting)"
15 echo " lock freq [volt] [dsp] - lock CPU at frequency with specific settings"
16 echo " unlock - unlock CPU frequency"
17 echo "filenames: absolute path or filename in search path or none=defaults"
18 echo "search path: .,/home/user/.kernel,/usr/share/kernel-power-settings/"
21 if test "`id -u`" -ne 0; then
22 sudo $0 $* # run as root
26 cfr=/sys/devices/system/cpu/cpu0/cpufreq
31 if test -f $pwr/vdd1_opps_vsel -a -f $pwr/dsp_opps_rate; then :
33 echo This kernel version `uname -r` is not supported
34 echo Please make sure that kernel-power is installed and running.
35 echo If you have just installed the kernel, you need to shutdown and boot to activate it.
36 echo To reinstall the power user kernel run:
37 echo \'apt-get install --reinstall kernel-power kernel-power-flasher\'
42 for f in `cat $cfr/scaling_available_frequencies`; do
45 vsel=`cat $pwr/vdd1_opps_vsel`
46 rate=`cat $pwr/dsp_opps_rate`
49 test "$cmd" = setdefault && cmd=default # old name
50 case " show load save default limits lock unlock " in
52 *) echo "invalid command $cmd"; exit 1 ;;
56 if test "$cmd" = unlock; then
57 echo 'unlocking frequency. reset to defaults'
60 if test "$cmd" = default && test $# -eq 0; then
61 echo 'saving current settings as defaults'
62 arg=/etc/default/kernel-power
66 popvsel() { curvsel=$1; shift; vsel="$*"; }
67 poprate() { currate=$1; shift; rate="$*"; }
71 minfreq=$((`cat $cfr/scaling_min_freq`/1000))
72 maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
73 test $maxfreq = 599 && maxfreq=600
74 gov=`cat $cfr/scaling_governor`
76 test $gov = ondemand && avoid=`cat $cfd/avoid_frequencies`
81 case " $avoid " in *" $f "*) ;;
82 *) freqs="$freqs$((f/1000)):$curvsel,$currate " ;;
85 if test $cmd = show; then
86 echo "current kernel configuration:"
87 echo "current frequency:" $((`cat $cfr/scaling_cur_freq`/1000))
88 echo -n "supported frequencies: "
89 for f in $allfreq; do echo -n "$((f/1000)) "; done
91 echo "min. frequency:" $minfreq
92 echo "max. frequency:" $maxfreq
93 echo -n "avoid frequencies: "
94 for f in $avoid; do echo -n "$((f/1000)) "; done
96 echo "active frequencies: $freqs"
97 echo "SmartReflex" "VDD1=`cat $pwr/sr_vdd1_autocomp`, VDD2=`cat $pwr/sr_vdd2_autocomp`"
98 echo -n "governor $gov:"
99 if test $gov = ondemand; then
100 echo -n " ignore nice load=" `cat $cfd/ignore_nice_load`
101 echo -n ", up threshold=" `cat $cfd/up_threshold`
102 echo -n ", sampling rate=" `cat $cfd/sampling_rate`
103 echo ", powersave bias=" `cat $cfd/powersave_bias`
108 test $cmd = save && arg=$1
109 if test -z "$arg"; then
110 echo "filename argument is mssing"
113 if test `basename $arg` = $arg; then
116 if test ! -d $u; then
121 chown user.users $arg
124 echo "saving to $arg"
125 echo "# kernel configuration file generated by $0" > $arg
126 echo "MINFREQ=$minfreq" >> $arg
127 echo "MAXFREQ=$maxfreq" >> $arg
128 echo "FREQS=\"$freqs\"" >> $arg
129 echo "SMARTREFLEX_VDD1=`cat $pwr/sr_vdd1_autocomp`" >> $arg
130 echo "SMARTREFLEX_VDD2=`cat $pwr/sr_vdd2_autocomp`" >> $arg
131 echo "GOVERNOR=$gov" >> $arg
132 if test $gov = ondemand; then
133 echo "IGNORE_NICE_LOAD=`cat $cfd/ignore_nice_load`" >> $arg
134 echo "UP_THRESHOLD=`cat $cfd/up_threshold`" >> $arg
135 echo "SAMPLING_RATE=`cat $cfd/sampling_rate`" >> $arg
136 echo "POWERSAVE_BIAS=`cat $cfd/powersave_bias`" >> $arg
141 test $cmd = loaddef || arg=$1
142 if test -z "$arg"; then
143 arg=/etc/default/kernel-power
144 test -f $arg || arg=/usr/share/kernel-power-settings/default
146 if test `basename $arg` = $arg; then # not absolute
147 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
148 test -f $p/$arg && arg=$p/$arg && break
151 if test ! -f "$arg"; then
152 echo "file not found $arg"
157 if test -n "$VDD1_OPPS_VSEL" -o -n "$DSP_OPPS_RATE"; then
158 echo "warning: old configuration format detected. please save in the new format."
159 if test -n "$MAX_FREQ"; then
160 test $MAX_FREQ = 600000 && MAX_FREQ=599000
161 echo $MAX_FREQ > $cfr/scaling_max_freq
163 test -n "$MIN_FREQ" && echo $MIN_FREQ > $cfr/scaling_min_freq
164 test -n "$MAX_FREQ" && echo $MAX_FREQ > $cfr/scaling_max_freq
165 test -n "$VDD1_OPPS_VSEL" && echo $VDD1_OPPS_VSEL > $pwr/vdd1_opps_vsel
166 test -n "$DSP_OPPS_RATE" && echo $DSP_OPPS_RATE > $pwr/dsp_opps_rate
167 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
168 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
169 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
170 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
171 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
178 freq=`echo $f | cut -d: -f1`
179 f=`echo $f | cut -d: -f2`
180 volt=`echo $f | cut -d, -f1`
181 dsp=`echo $f | cut -d, -f2`
182 if test ! $freq = 0; then
183 test -z "$minfreq" -o "$freq" -lt "$minfreq" && minfreq=$freq
184 test -z "$maxfreq" -o "$freq" -gt "$maxfreq" && maxfreq=$freq
186 if test "$freq" = "750000"; then
187 echo warning: $freq was changed to 720000;
190 case " $allfreq " in *" $freq "*) ;;
191 *) echo warning: $freq not supported; continue ;;
193 active="$active $freq"
195 test -z "$volt" && test -z "$dsp" && continue
198 for fr in $allfreq; do
199 if test $fr = $freq; then
202 test -z "$volt" && volt=$curvsel
203 test -z "$dsp" && dsp=$currate
204 tvsel="$tvsel $volt $vsel"
205 trate="$trate $dsp $rate"
209 tvsel="$tvsel $curvsel"
211 trate="$trate $currate"
216 test -z "$GOVERNOR" && GOVERNOR=ondemand
217 test -n "$MINFREQ" && minfreq=$MINFREQ
218 test -n "$MAXFREQ" && maxfreq=$MAXFREQ
219 test "$minfreq" -gt 100000 && minfreq=$((minfreq/1000))
220 test "$maxfreq" -gt 100000 && maxfreq=$((maxfreq/1000))
222 for f in $allfreq; do
223 if test "$f" -lt $((minfreq*1000)); then
227 case " $active " in *" $f "*) ;;
228 *) avoid="$avoid $f" ;;
231 echo $GOVERNOR > $cfr/scaling_governor
232 if test $GOVERNOR = ondemand; then
233 echo $avoid > $cfd/avoid_frequencies
234 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
235 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
236 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
237 test -n "$POWERSAVE_BIAS" && echo $POWERSAVE_BIAS > $cfd/powersave_bias
239 echo $vsel > $pwr/vdd1_opps_vsel
240 echo $rate > $pwr/dsp_opps_rate
241 test $maxfreq = 600 && maxfreq=599
242 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
243 echo $((minfreq*1000)) > $cfr/scaling_min_freq
244 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
245 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
246 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
247 echo "successfully loaded."
251 if test -z "$arg"; then
252 echo "filename missing"
255 if test `basename $arg` = $arg; then # not absolute
256 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
257 test -f $p/$arg && arg=$p/$arg && break
260 def=/etc/default/kernel-power
263 /usr/share/kernel-power-settings/*) ln -s $arg $def ;;
266 echo "defaults set to $arg"
271 if test "x$minfreq" = x -o "x$maxfreq" = x; then
272 echo "frequency limit arguments missing"
275 test "x$minfreq" = "x-" && minfreq=$((`cat $cfr/scaling_min_freq`/1000))
276 test "x$maxfreq" = "x-" && maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
277 limits="$minfreq,$maxfreq"
278 minfreq=$((minfreq*1000))
279 maxfreq=$((maxfreq*1000))
280 case " $allfreq " in *" $minfreq "*) ;;
281 *) echo "invalid lower limit $1"; exit 1; ;;
283 case " $allfreq " in *" $maxfreq "*) ;;
284 *) echo "invalid upper limit $2"; exit 1; ;;
286 if test $minfreq -gt $maxfreq; then
287 echo "minimum must not be greater than maximum: $limits"
290 test $maxfreq = 600000 && maxfreq=599000
291 echo $maxfreq > $cfr/scaling_max_freq
292 echo $minfreq > $cfr/scaling_min_freq
293 echo $maxfreq > $cfr/scaling_max_freq
294 echo "the limits were set to [$limits]"
299 for f in $allfreq; do
300 test "$f" = "$arg" && continue
310 for f in $allfreq; do
312 if test $f = $freq; then
318 if test -z "ifreq"; then
319 echo invalid frequency $freq
322 echo userspace > $cfr/scaling_governor
323 echo $altfreq > $cfr/scaling_setspeed # temporarily set alternative frequencies
325 if test -n "$volt"; then
328 for v in `cat $pwr/vdd1_opps_vsel`; do
330 test $i = $ifreq && v=$volt
333 echo $vsel > $pwr/vdd1_opps_vsel
336 if test -n "$dsp"; then
339 for r in `cat $pwr/dsp_opps_rate`; do
341 test $i = $ifreq && r=$dsp
344 echo $dsp > $pwr/dsp_opps_rate
346 echo locking frequency $freq
347 echo ondemand > $cfr/scaling_governor
348 echo $avoid > $cfd/avoid_frequencies # avoid all other freqs
350 test $maxfreq = 600000 && maxfreq=599000
351 # min after max? kernel docs are wrong?
352 echo $maxfreq > $cfr/scaling_max_freq
353 echo $freq > $cfr/scaling_min_freq
354 echo $maxfreq > $cfr/scaling_max_freq