#! /bin/sh
#
# Laptop mode tools module to handle CPU Hot Plugging
#


if [ x$CONTROL_CPU_HOTPLUG = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_CPU_HOTPLUG = xauto ]; then
	if [ $ON_AC -eq 1 ] ; then
		if [ "$ACTIVATE" -eq 1 ] ; then
			ECHO_VAL="$LM_AC_CPU_HOTPLUG"
		else
			ECHO_VAL="$NOLM_AC_CPU_HOTPLUG"
		fi
	else
		ECHO_VAL="$BATT_CPU_HOTPLUG"
	fi

	# To disable the CPU, write 0. So flip it here.
	if [ x$ECHO_VAL = x1 ]; then
		CPU_VAL=0;
	else
		CPU_VAL=1;
	fi

	for THISCPU in /sys/devices/system/cpu/cpu[0-9]* ; do
		if [ -e "$THISCPU/online" ]; then
			log "VERBOSE" "Bringing CPU $THISCPU to $ECHO_VAL";
			echo $CPU_VAL > $THISCPU/online;
		else
			log "VERBOSE" "CPU $THISCPU cannot be hot plugged";
		fi
	done
fi
