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