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