--- apmscript.ORIG        2004-10-19 15:46:06.000000000 -0700
+++ apmscript        2004-11-11 08:42:03.529019880 -0800
@@ -5,6 +5,16 @@
 # (c) 1999-2002 Bernhard Rosenkraenzer <bero@redhat.com>
 # (c) 2003 Red Hat, Inc.
 #
+# 2004.10.19 wdw modified to support new sysfs cpufreq interface and governors
+#            and configure power mode at script start as well as at power change
+#            similar cmds now in 3 places - would make a nice function
+#
+# 2004.11.08 wdw moved the start) apmcontinue call to the end of start where it
+#            belongs
+#
+# 2004.11.11 wdw mod resume) to set services and laptop mode too
+#            put all this stuff into a function
+#
 # DO NOT EDIT THIS SCRIPT, CREATE AND EDIT apmcontinue IN THIS DIRECTORY; you
 # can put your stuff into apmcontinue for every link you create to apmscript;
 # for a start and definitely enough for most laptops we have two links and
@@ -14,6 +24,8 @@
 # reinitialising some PCMCIA-Card) there; apmcontinue will get the name
 # as which it was called as $1; for debugging see the logfiles
 #
+# wdw NOTE: apmcontinue actually gets called at resume too (this is good...)
+#
 # If you think something in this script needs to be changed anyway, please
 # report it to http://bugzilla.redhat.com/bugzilla/
 #
@@ -30,11 +42,48 @@
 [ -z "$CHANGEVT" ] && CHANGEVT="0"
 [ -z "$CLOCK_SYNC" ] && CLOCK_SYNC="no"
 [ -z "$CPUFREQ" ] && CPUFREQ="no"
+[ -z "$AC_ONLINE_GOVERNOR" ] && AC_ONLINE_GOVERNOR="performance"
+[ -z "$AC_OFFLINE_GOVERNOR" ] && AC_OFFLINE_GOVERNOR="powersave"
 if [ -n "`/sbin/pidof X`" ]; then
         X_RUNNING=1
 fi
 
-if [ ! -f /proc/cpufreq ]; then
+# set cpufreq governor, laptop mode, and services appropriate
+# to AC or battery operation
+check_power()
+{
+        # change from performance to powersave or vice versa based
+        # on whether we're running on battery or ac power
+        if test "x$CPUFREQ" = "xyes"; then
+            if apm | LC_ALL=C grep -q on-line &>/dev/null; then
+                echo -n "$AC_ONLINE_GOVERNOR" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+            else
+                echo -n "$AC_OFFLINE_GOVERNOR" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+            fi
+        fi
+
+        # Change from battery power to AC power or vice versa.
+        if apm | LC_ALL=C grep -q on-line &>/dev/null; then
+                [ -f /proc/sys/vm/laptop_mode ] && echo 0 > /proc/sys/vm/laptop_mode
+                what="start"
+                if [ -n "$LOWPOWER_SERVICES" -a -e /var/run/apmd/LOW_POWER ]; then
+                        rm -f /var/run/apmd/LOW_POWER
+                        for i in $LOWPOWER_SERVICES; do
+                                /sbin/service $i start
+                        done
+                fi
+        else
+                what="stop"
+                [ -f /proc/sys/vm/laptop_mode ] && echo 1 > /proc/sys/vm/laptop_mode
+        fi
+        if [ -n "$POWER_SERVICES" ]; then
+                for i in $POWER_SERVICES; do
+                        /sbin/service $i $what
+                done
+        fi
+}
+
+if [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ]; then
     CPUFREQ="no"
 fi
 
@@ -273,6 +322,9 @@
 
         sync
 
+        # set cpufreq governor, laptop mode, and services
+        check_power
+
         [ -f /etc/sysconfig/apm-scripts/apmcontinue ] && . /etc/sysconfig/apm-scripts/apmcontinue "$@"
 
         # Finally, run anacron to catch up cron stuff we missed...
@@ -286,14 +338,6 @@
                 fi
         fi
 
-        if test "x$CPUFREQ" = "xyes"; then
-            if apm | LC_ALL=C grep -q on-line &>/dev/null; then
-                echo -n "0%100%100%performance" > /proc/cpufreq
-            else
-                echo -n "0%0%0%powersave" > /proc/cpufreq
-            fi
-        fi
-                 
         if test "x$HDPARM_AT_RESUME" != "x"; then
                 for i in /proc/ide/hd*; do
                         DRIVE=/dev/`echo $i |sed -e "s,.*/,,g"`
@@ -309,35 +353,8 @@
         [ -f /etc/sysconfig/apm-scripts/apmcontinue-pre ] && /etc/sysconfig/apm-scripts/apmcontinue-pre "$@"
         case $2 in
         power)
-                # change from performance to powersave or vice versa based
-                # on whether we're running on battery or ac power
-                if test "x$CPUFREQ" = "xyes"; then
-                    if apm | LC_ALL=C grep -q on-line &>/dev/null; then
-                        echo -n "0%100%100%performance" > /proc/cpufreq
-                    else
-                        echo -n "0%0%0%powersave" > /proc/cpufreq
-                    fi
-                fi
-
-                # Change from battery power to AC power or vice versa.
-                if apm | LC_ALL=C grep -q on-line &>/dev/null; then
-                        [ -f /proc/sys/vm/laptop_mode ] && echo 0 > /proc/sys/vm/laptop_mode
-                        what="start"
-                        if [ -n "$LOWPOWER_SERVICES" -a -e /var/run/apmd/LOW_POWER ]; then
-                                rm -f /var/run/apmd/LOW_POWER
-                                for i in $LOWPOWER_SERVICES; do
-                                        /sbin/service $i start
-                                done
-                        fi
-                else
-                        what="stop"
-                        [ -f /proc/sys/vm/laptop_mode ] && echo 1 > /proc/sys/vm/laptop_mode
-                fi
-                if [ -n "$POWER_SERVICES" ]; then
-                        for i in $POWER_SERVICES; do
-                                /sbin/service $i $what
-                        done
-                fi
+                # set cupfreq governor, laptop mode, services
+                check_power
                 ;;
         battery)
                 # Battery low. If you want to be on the safe side, maybe put
@@ -357,7 +374,10 @@
     start)
         # This occurs at system startup - you usually don't need to do
         # anything here.
+        # wdw NOTE: ahem, not quite....
         [ -f /etc/sysconfig/apm-scripts/apmcontinue-pre ] && /etc/sysconfig/apm-scripts/apmcontinue-pre "$@"
+        # set cpufreq governor, laptop mode, and services
+        check_power
         [ -f /etc/sysconfig/apm-scripts/apmcontinue ] && . /etc/sysconfig/apm-scripts/apmcontinue $@
         ;;
     stop)