#!/bin/sh
########################################################################
# Begin $rc_base/init.d/cpufreq
#
# Description : Initalisize and startup cpufreq and set a governor
#
# Authors     : Arne Fitzenreiter - arne_f@ipfire.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
	start)
		boot_mesg -n "Starting cpufreq... "

		# try cpufreq hardware depend modules
		for module in acpi-cpufreq cpufreq-nforce2 e-powersaver \
		    gx-suspmod longhaul longrun p4-clockmod powernow-k6 \
		    powernow-k7 powernow-k8 speedstep-centrino speedstep-ich \
		    speedstep-smi; do
		    modprobe $module > /dev/null 2>&1;
		    if [ ${?} = 0 ]; then
			boot_mesg -n "$SUCCESS$module$NORMAL "
		    fi
		done
		boot_mesg ""

		# load cqufreq governors
		modprobe cpufreq_conservative
		modprobe cpufreq_ondemand
		modprobe cpufreq_powersave
		modprobe cpufreq_userspace

		# Set the governor to ondemand 
		cpufreq-set -g ondemand
		if [ ${?} = 0 ]; then
		    # activate cpufreq collectd module
		    sed -i -e "s|#LoadPlugin cpufreq|LoadPlugin cpufreq|g" /etc/collectd.conf
		    echo_ok;
		else
		    echo_failure;
		fi
		exit 0;
		;;
	*)
		echo "Usage: ${0} {start}"
		exit 1
		;;
esac

# End $rc_base/init.d/cpufreq
