Re: [PATCH] fix APM notify of apmd for on-AC/on-battery transitions

From: Ray Lee (ray-lk@madrabbit.org)
Date: Sun Jul 28 2002 - 20:22:20 EST


On Fri, 2002-07-26 at 19:17, cort@fsmlabs.com wrote:
> I think this affects all Vaio laptops. With enough reports maybe
> we'll find out something different, though.

Agreed to both.

> Thanks for the suggestion to move the get_event(). I'll see about moving
> that (but not on a friday night).

Heh, you mean you have a life? I'm jealous :-)

Below is my suggestion for the patch. Mostly it's just a rework of the
structure, but one thing that cropped up is that 2.4.18 got rid of the
send_event() call. Also, as you'll note from the patch I'm suggesting we
back off from identifying systems one by one, and instead just always do
the right thing: if the BIOS decides to step up and take responsibility
for power change events, then disable the workaround code. Otherwise,
let it be and send a notification as if the BIOS had done it correctly
to begin with.

Comments?

diff -NurX dontdiff linux/arch/i386/kernel/apm.c apm-fixes/arch/i386/kernel/apm.c
--- linux/arch/i386/kernel/apm.c 2002-06-08 08:31:24.000000000 -0700
+++ apm-fixes/arch/i386/kernel/apm.c 2002-07-28 17:48:42.000000000 -0700
@@ -385,6 +385,7 @@
 static int ignore_sys_suspend;
 static int ignore_normal_resume;
 static int bounce_interval = DEFAULT_BOUNCE_INTERVAL;
+static u_short last_power_status;
 
 #ifdef CONFIG_APM_RTC_IS_GMT
 # define clock_cmos_diff 0
@@ -1240,15 +1241,40 @@
         apm_eventinfo_t info;
 
         static int notified;
+ static u_short power_event_state = 0;
 
         /* we don't use the eventinfo */
         error = apm_get_event(&event, &info);
- if (error == APM_SUCCESS)
+ if (error == APM_SUCCESS) {
+ /* if BIOS reports power changes, disable workaround */
+ if (event == APM_POWER_STATUS_CHANGE)
+ power_event_state = 2;
                 return event;
+ }
 
         if ((error != APM_NO_EVENTS) && (notified++ == 0))
                 apm_error("get_event", error);
 
+ /*
+ * Sony Vaios don't seem to want to notify us about AC line power
+ * status changes. So for those and any others like them, we keep
+ * track of it by hand and emulate it here.
+ */
+ if (power_event_state < 2) {
+ u_short status, bat, life;
+ error = apm_get_power_status(&status, &bat, &life);
+ if (error == APM_SUCCESS && (status ^ last_power_status) & 0xff00) {
+ /* fake an APM_POWER_STATUS_CHANGE event */
+ last_power_status = status;
+ if (power_event_state == 0) {
+ printk(KERN_WARNING "apm: power status notification workaround enabled\n");
+ power_event_state = 1;
+ }
+ return APM_POWER_STATUS_CHANGE;
+ } else if (error != APM_SUCCESS)
+ power_event_state=2;
+ }
+
         return 0;
 }
 
@@ -1758,6 +1784,7 @@
 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
                 console_blank_hook = apm_console_blank;
 #endif
+ apm_get_power_status(&last_power_status, &cx, &dx);
                 apm_mainloop();
 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
                 console_blank_hook = NULL;

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



This archive was generated by hypermail 2b29 : Tue Jul 30 2002 - 14:00:31 EST