Update soundtest
[grml-scripts.git] / usr_bin / cpufreq-detect.sh
1 #!/bin/sh
2 # Filename:      cpufreq-detect.sh
3 # Purpose:       detect cpu type and set $MODULE to appropriate kernel module for cpufrequency scaling
4 # Authors:       grml-team (grml.org), (C) Ubuntu, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mit Jul 04 12:15:57 CEST 2007 [mika]
8 ################################################################################
9 # Notice: also check out /etc/init.d/loadcpufreq of current cpufrequtils in Debian.
10 #
11 # Notice: based on http://people.ubuntulinux.org/~scott/patches/powernowd/ and
12 # scripts found in the powernowd package version 0.97-1ubuntu6 on Ubuntu.
13 ################################################################################
14
15 /usr/sbin/laptop-detect 2>/dev/null && LAPTOP=1
16
17 CPUINFO=/proc/cpuinfo
18 IOPORTS=/proc/ioports
19
20 if [ ! -f $CPUINFO ] ; then
21    echo >&2 $CPUINFO not detected...
22    exit 1
23 fi
24
25 # /lib/modules/2.6.16-grml/kernel/arch/i386/kernel/cpu/cpufreq/ ->
26 # modulename          [used?]
27 # acpi-cpufreq        [x]
28 # cpufreq-nforce2     [ ] nForce2 FSB changing cpufreq driver
29 # gx-suspmod          [ ] Cpufreq driver for Cyrix MediaGX and NatSemi Geode
30 # longhaul            [x]
31 # longrun             [x]
32 # p4-clockmod         [~] cpufreq driver for Pentium(TM) 4/Xeon(TM)
33 # powernow-k6         [x]
34 # powernow-k7         [x]
35 # powernow-k8         [x]
36 # speedstep-centrino  [x]
37 # speedstep-ich       [x]
38 # speedstep-lib       [ ] Library for Intel SpeedStep 1 or 2 cpufreq drivers.
39 # speedstep-smi       [x]
40 #
41 # /lib/modules/2.6.16-grml/kernel/drivers/cpufreq ->
42 # cpufreq_conservative
43 # cpufreq_ondemand
44 # cpufreq_powersave
45 # cpufreq_stats
46 # cpufreq_userspace
47 # freq_table
48
49 MODEL_NAME=`grep '^model name' "$CPUINFO" | head -n 1 | sed -e 's/^.*: //;'`
50 CPU=`grep -E '^cpud[^:]+:' "$CPUINFO" | head -n 1 | sed -e 's/^.*: //;'`
51 VENDOR_ID=`grep -E '^vendor_id[^:]+:' "$CPUINFO" | head -n 1 | sed -e 's/^.*: //;'`
52 CPU_FAMILY=$(sed -e '/^cpu family/ {s/.*: //;p;Q};d' $CPUINFO)
53
54 MODULE=none
55 MODULE_FALLBACK=acpi-cpufreq
56
57 # Two modules for PIII-M depending the chipset.
58 # modprobe speedstep-ich$EXT || modprobe speestep-smi$EXT  would be another way
59 if [ -f $IOPORTS ] && grep -q 'Intel .*ICH' $IOPORTS ; then
60   PIII_MODULE=speedstep-ich
61 else
62   PIII_MODULE=speedstep-smi
63 fi
64
65 case "$VENDOR_ID" in
66     GenuineIntel*)
67     # If the CPU has the est flag, it supports enhanced speedstep and should
68     # use the speedstep-centrino driver
69     if [ "$(grep est $CPUINFO)" ]; then
70         case "$(uname -r)" in
71             2.6.2[0-9]*)
72                 # Prefer acpi-cpufreq for kernels after 2.6.20
73                 MODULE=acpi-cpufreq
74                 ;;
75             *)
76                 MODULE=speedstep-centrino
77                 ;;
78         esac
79     elif [ $CPU_FAMILY = 15 ]; then
80     # Right. Check if it's a P4 without est.
81         # Could be speedstep-ich, or could be p4-clockmod.
82         MODULE=speedstep-ich;
83         # Disabled for now - the latency tends to be bad enough to make it
84         # fairly pointless.
85         # echo "FREQDRIVER=p4-clockmod" >/etc/default/powernowd
86         # to override this
87         #if [ $LAPTOP = "1" ]; then
88         #    MODULE_FALLBACK=p4-clockmod;
89         #fi
90     else
91     # So it doesn't have Enhanced Speedstep, and it's not a P4. It could be
92     # a Speedstep PIII, or it may be unsupported. There's no terribly good
93     # programmatic way of telling.
94         case "$MODEL_NAME" in
95             Intel\(R\)\ Pentium\(R\)\ III\ Mobile\ CPU*)
96             MODULE=$PIII_MODULE ;;
97
98         # JD: says this works with   cpufreq_userspace
99             Mobile\ Intel\(R\)\ Pentium\(R\)\ III\ CPU\ -\ M*)
100             MODULE=$PIII_MODULE ;;
101
102         # https://bugzilla.ubuntu.com/show_bug.cgi?id=4262
103         # UNCONFIRMED
104             Pentium\ III\ \(Coppermine\)*)
105             MODULE=$PIII_MODULE ;;
106
107             Intel\(R\)\ Celeron\(R\)\ M\ processor*)
108             MODULE=p4-clockmod ;;
109
110         esac
111     fi
112     ;;
113     AuthenticAMD*)
114     # Hurrah. This is nice and easy.
115     case $CPU_FAMILY in
116         5)
117         # K6
118         MODULE=powernow-k6
119         ;;
120         6)
121         # K7
122         MODULE=powernow-k7
123         ;;
124         15)
125         # K8
126         MODULE=powernow-k8
127         ;;
128     esac
129     ;;
130     CentaurHauls*)
131     # VIA
132     if [ $CPU_FAMILY == 6 ]; then
133         MODULE=longhaul;
134     fi
135     ;;
136     GenuineTMx86*)
137     # Transmeta
138     if [ "`grep longrun $CPUINFO`" ]; then
139         MODULE=longrun
140     fi
141     ;;
142 esac
143
144 ## END OF FILE #################################################################