[PATCH] APM cleanups

From: Stephen Rothwell (sfr@linuxcare.com)
Date: Mon Jul 10 2000 - 21:57:51 EST


Hi Linus,

Prodded by the -Werror in the test3pre's, I have made the following
patch again 2.4.0tes3. It also removes the explicit 0 initilaization
of statics and remove the CONFIG_APM_IGNORE_SUSPEND_BOUNCE option
and mokes the bounce interval configurable at run time.

Please apply.

Cheers,
Stephen Rothwell sfr@linuxcare.com

diff -ruN 2.4.0-test3/Documentation/Configure.help 2.4.0-test3-apm/Documentation/Configure.help
--- 2.4.0-test3/Documentation/Configure.help Tue Jul 11 12:07:51 2000
+++ 2.4.0-test3-apm/Documentation/Configure.help Tue Jul 11 12:17:39 2000
@@ -12615,15 +12615,6 @@
   backlight at all, or it might print a lot of errors to the console,
   especially if you are using gpm.
 
-Ignore multiple suspend/resume cycles
-CONFIG_APM_IGNORE_SUSPEND_BOUNCE
- This option is necessary on the Dell Inspiron 3200 and others, but
- should be safe for all other laptops. When enabled, a system suspend
- event that occurs within three seconds of a resume is ignored.
- Without this the Inspiron will shut itself off a few seconds after
- you open the lid, requiring you to press the power button to resume
- it a second time. Say Y.
-
 RTC stores time in GMT
 CONFIG_APM_RTC_IS_GMT
   Say Y here if your RTC (Real Time Clock a.k.a. hardware clock)
diff -ruN 2.4.0-test3/arch/i386/config.in 2.4.0-test3-apm/arch/i386/config.in
--- 2.4.0-test3/arch/i386/config.in Tue Jul 11 12:07:52 2000
+++ 2.4.0-test3-apm/arch/i386/config.in Tue Jul 11 12:17:39 2000
@@ -225,7 +225,6 @@
    bool ' Enable PM at boot time' CONFIG_APM_DO_ENABLE
    bool ' Make CPU Idle calls when idle' CONFIG_APM_CPU_IDLE
    bool ' Enable console blanking using APM' CONFIG_APM_DISPLAY_BLANK
- bool ' Ignore multiple suspend/resume cycles' CONFIG_APM_IGNORE_SUSPEND_BOUNCE
    bool ' RTC stores time in GMT' CONFIG_APM_RTC_IS_GMT
    bool ' Allow interrupts during APM BIOS calls' CONFIG_APM_ALLOW_INTS
    bool ' Use real mode APM BIOS call to power off' CONFIG_APM_REAL_MODE_POWER_OFF
diff -ruN 2.4.0-test3/arch/i386/kernel/apm.c 2.4.0-test3-apm/arch/i386/kernel/apm.c
--- 2.4.0-test3/arch/i386/kernel/apm.c Tue Jul 11 12:07:52 2000
+++ 2.4.0-test3-apm/arch/i386/kernel/apm.c Tue Jul 11 12:30:27 2000
@@ -142,6 +142,8 @@
  * <andy_henroid@yahoo.com> fixed by sfr).
  * Make power off work on SMP again (Tony Hoyle
  * <tmh@magenta-logic.com> and <zlatko@iskon.hr>) modified by sfr.
+ * Remove CONFIG_APM_SUSPEND_BOUNCE. The bounce ignore
+ * interval is now configurable.
  *
  * APM 1.1 Reference:
  *
@@ -178,6 +180,7 @@
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/pm.h>
+#include <linux/kernel.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -267,10 +270,9 @@
 #define APM_CHECK_TIMEOUT (HZ)
 
 /*
- * If CONFIG_APM_IGNORE_SUSPEND_BOUNCE is defined then
- * ignore suspend events for this amount of time after a resume
+ * Ignore suspend events for this amount of time after a resume
  */
-#define BOUNCE_INTERVAL (3 * HZ)
+#define DEFAULT_BOUNCE_INTERVAL (3 * HZ)
 
 /*
  * Save a segment register away
@@ -314,28 +316,30 @@
         unsigned short segment;
 } apm_bios_entry;
 #ifdef CONFIG_APM_CPU_IDLE
-static int clock_slowed = 0;
+static int clock_slowed;
 #endif
-static int suspends_pending = 0;
-static int standbys_pending = 0;
-static int waiting_for_resume = 0;
+static int suspends_pending;
+static int standbys_pending;
+static int waiting_for_resume;
+static int ignore_normal_resume;
+static int bounce_interval = DEFAULT_BOUNCE_INTERVAL;
 
 #ifdef CONFIG_APM_RTC_IS_GMT
 # define clock_cmos_diff 0
 # define got_clock_diff 1
 #else
 static long clock_cmos_diff;
-static int got_clock_diff = 0;
+static int got_clock_diff;
 #endif
-static int debug = 0;
-static int apm_disabled = 0;
+static int debug;
+static int apm_disabled;
 #ifdef CONFIG_SMP
-static int power_off = 0;
+static int power_off;
 #else
 static int power_off = 1;
 #endif
-static int exit_kapmd = 0;
-static int kapmd_running = 0;
+static int exit_kapmd;
+static int kapmd_running;
 
 static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
 static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
@@ -912,16 +916,16 @@
         set_time();
         if (err == APM_NO_ERROR)
                 err = APM_SUCCESS;
- if (err != APM_SUCCESS) {
+ if (err != APM_SUCCESS)
                 apm_error("suspend", err);
- send_event(APM_NORMAL_RESUME);
- sti();
- queue_event(APM_NORMAL_RESUME, NULL);
- }
+ send_event(APM_NORMAL_RESUME);
+ sti();
+ queue_event(APM_NORMAL_RESUME, NULL);
         for (as = user_list; as != NULL; as = as->next) {
                 as->suspend_wait = 0;
                 as->suspend_result = ((err == APM_SUCCESS) ? 0 : -EIO);
         }
+ ignore_normal_resume = 1;
         wake_up_interruptible(&apm_suspend_waitqueue);
         return err;
 }
@@ -942,7 +946,7 @@
         apm_event_t event;
         apm_eventinfo_t info;
 
- static int notified = 0;
+ static int notified;
 
         /* we don't use the eventinfo */
         error = apm_get_event(&event, &info);
@@ -958,10 +962,8 @@
 static void check_events(void)
 {
         apm_event_t event;
-#ifdef CONFIG_APM_IGNORE_SUSPEND_BOUNCE
- static unsigned long last_resume = 0;
- static int ignore_bounce = 0;
-#endif
+ static unsigned long last_resume;
+ static int ignore_bounce;
 
         while ((event = get_event()) != 0) {
                 if (debug) {
@@ -972,11 +974,12 @@
                                 printk(KERN_DEBUG "apm: received unknown "
                                        "event 0x%02x\n", event);
                 }
-#ifdef CONFIG_APM_IGNORE_SUSPEND_BOUNCE
                 if (ignore_bounce
- && ((jiffies - last_resume) > BOUNCE_INTERVAL))
+ && ((jiffies - last_resume) > bounce_interval))
                         ignore_bounce = 0;
-#endif
+ if (ignore_normal_resume && (event != APM_NORMAL_RESUME))
+ ignore_normal_resume = 0;
+
                 switch (event) {
                 case APM_SYS_STANDBY:
                 case APM_USER_STANDBY:
@@ -994,10 +997,11 @@
                         break;
 #endif
                 case APM_SYS_SUSPEND:
-#ifdef CONFIG_APM_IGNORE_SUSPEND_BOUNCE
- if (ignore_bounce)
+ if (ignore_bounce) {
+ if (apm_bios_info.version > 0x100)
+ apm_set_power_state(APM_STATE_REJECT);
                                 break;
-#endif
+ }
                         /*
                          * If we are already processing a SUSPEND,
                          * then further SUSPEND events from the BIOS
@@ -1020,14 +1024,14 @@
                 case APM_CRITICAL_RESUME:
                 case APM_STANDBY_RESUME:
                         waiting_for_resume = 0;
-#ifdef CONFIG_APM_IGNORE_SUSPEND_BOUNCE
                         last_resume = jiffies;
                         ignore_bounce = 1;
-#endif
- set_time();
- send_event(event);
- sti();
- queue_event(event, NULL);
+ if ((event != APM_NORMAL_RESUME)
+ || (ignore_normal_resume == 0)) {
+ set_time();
+ send_event(event);
+ queue_event(event, NULL);
+ }
                         break;
 
                 case APM_CAPABILITY_CHANGE:
@@ -1519,6 +1523,7 @@
         return 0;
 }
 
+#ifndef MODULE
 static int __init apm_setup(char *str)
 {
         int invert;
@@ -1536,6 +1541,9 @@
                 if ((strncmp(str, "power-off", 9) == 0) ||
                     (strncmp(str, "power_off", 9) == 0))
                         power_off = !invert;
+ if ((strncmp(str, "bounce-interval=", 16) == 0) ||
+ (strncmp(str, "bounce_interval=", 16) == 0))
+ bounce_interval = simple_strtol(str + 16, NULL, 0);
                 str = strchr(str, ',');
                 if (str != NULL)
                         str += strspn(str, ", \t");
@@ -1544,6 +1552,7 @@
 }
 
 __setup("apm=", apm_setup);
+#endif
 
 static struct file_operations apm_bios_fops = {
         owner: THIS_MODULE,
@@ -1702,5 +1711,9 @@
 MODULE_DESCRIPTION("Advanced Power Management");
 MODULE_PARM(debug, "i");
 MODULE_PARM_DESC(debug, "Enable debug mode");
+MODULE_PARM(power_off, "i");
+MODULE_PARM_DESC(power_off, "Enable power off");
+MODULE_PARM(bounce_interval, "i");
+MODULE_PARM_DESC(bounce_interval, "Set the number of ticks to ignore suspend bounces");
 
 EXPORT_NO_SYMBOLS;
diff -ruN 2.4.0-test3/arch/i386/kernel/i386_ksyms.c 2.4.0-test3-apm/arch/i386/kernel/i386_ksyms.c
--- 2.4.0-test3/arch/i386/kernel/i386_ksyms.c Tue Jun 27 14:52:21 2000
+++ 2.4.0-test3-apm/arch/i386/kernel/i386_ksyms.c Tue Jul 11 12:17:39 2000
@@ -11,6 +11,7 @@
 #include <linux/pm.h>
 #include <linux/pci.h>
 #include <linux/apm_bios.h>
+#include <linux/kernel.h>
 
 #include <asm/semaphore.h>
 #include <asm/processor.h>
@@ -89,6 +90,7 @@
 
 EXPORT_SYMBOL(strtok);
 EXPORT_SYMBOL(strpbrk);
+EXPORT_SYMBOL(simple_strtol);
 
 EXPORT_SYMBOL(strncpy_from_user);
 EXPORT_SYMBOL(__strncpy_from_user);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:12 EST