public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix APM notify of apmd for on-AC/on-battery transitions
@ 2002-07-26 20:33 Cort Dougan
  2002-07-26 21:33 ` Dave Jones
  0 siblings, 1 reply; 10+ messages in thread
From: Cort Dougan @ 2002-07-26 20:33 UTC (permalink / raw)
  To: linux-kernel

This patch fixes a problem with Sony Vaio laptops where they don't notify
the kernel of power source change events.  That means apmd is never told
and many of the apmd features can't be used.

The Sony Vaio that I have doesn't send APM events to the kernel telling it
about 'going on battery' or 'going on AC power' events.  It will register
them correctly if they're queried but it won't asynchronously send an event
so the kernel never tells apmd about it.

This patch fixes the situation by checking against the last known power
state (and power source) in the check_status() call.

This was tested on a Sony Vaio z505js, model PCG-5201 and it works
beautifully.  I'm told other Vaio notebooks have this same problem.  Now,
Vaio users can setup apmd to aggressively try to save power when on battery
or perform other crazy tasks.

This patch is against v2.4.16 but applies to newer kernels as well.

diff -Nru a/arch/i386/kernel/apm.c b/arch/i386/kernel/apm.c
--- a/arch/i386/kernel/apm.c	Fri Jul 26 14:29:55 2002
+++ b/arch/i386/kernel/apm.c	Fri Jul 26 14:29:55 2002
@@ -1313,6 +1313,34 @@
 			break;
 		}
 	}
+
+	/*
+	 * The Sony Vaio doesn't seem to want to send us a notify
+	 * about AC line power status changes.  So, we have to keep track
+	 * of it by hand and emulate it here.
+	 *   -- Cort <cort@fsmlabs.com>
+	 */
+	if ( is_sony_vaio_laptop ) {
+		static int last_status = 0;
+		u_short status, bat, life;
+
+		/* get the current power state */
+		if ( apm_get_power_status(&status, &bat, &life) !=
+		     APM_SUCCESS ) {
+			printk("%s:%s error checking power status\n",
+			       __FILE__,__FUNCTION__);
+		}
+		
+		/* has the status changed since we were last here? */
+		if (((status >> 8) & 0xff) != last_status) {
+			last_status = (status >> 8) & 0xff;
+			
+			/* fake a APM_POWER_STATUS_CHANGE event */
+			send_event(APM_POWER_STATUS_CHANGE);
+			queue_event(APM_POWER_STATUS_CHANGE, NULL);
+		}
+		
+	}
 }
 
 static void apm_event_handler(void)

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [PATCH] fix APM notify of apmd for on-AC/on-battery transitions
@ 2002-07-26 23:42 Ray Lee
  2002-07-27  2:17 ` cort
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Lee @ 2002-07-26 23:42 UTC (permalink / raw)
  To: cort; +Cc: Linux Kernel

Hi there Cort,

It looks like my Vaio will need it as well -- loading the apm module
with debug=1 doesn't show any on/off battery events when I yank the
power. (It does log other events, though.)

A comment on the patch? How about pushing the specifics of the
apm_bios_power_change_bug from check_events() down into either the
get_event() or apm_get_event() routines? That way the specifics are
abstracted a bit from the main event dispatch loop, and one gets to
inherit the debug logging and whatnot.

And, in case you decide to tighten up the dmi matching, my laptop info
follows:

	BIOS Information Block
		Vendor: Phoenix Technologies LTD
		Version: R0117A0
		Release: 04/25/00
	System Information Block
		Vendor: Sony Corporation    
		Product: PCG-XG29(UC)        

Thanks,

Ray




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-07-29  1:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-26 20:33 [PATCH] fix APM notify of apmd for on-AC/on-battery transitions Cort Dougan
2002-07-26 21:33 ` Dave Jones
2002-07-26 21:28   ` Cort Dougan
2002-07-26 21:22     ` John D. Kim
2002-07-26 22:26   ` [PATCH] fix APM notify of apmd for on-AC/on-battery transitions Cort Dougan
2002-07-26 22:47     ` Dave Jones
2002-07-26 22:50       ` Cort Dougan
  -- strict thread matches above, loose matches on Subject: below --
2002-07-26 23:42 Ray Lee
2002-07-27  2:17 ` cort
2002-07-29  1:22   ` Ray Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox