public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ray Lee <ray-lk@madrabbit.org>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Cc: cort@fsmlabs.com, alan@lxorguk.ukuu.org.uk
Subject: [PATCH] Guarantee APM power status change notifications
Date: 31 Jul 2002 11:33:10 -0700	[thread overview]
Message-ID: <1028140392.1771.66.camel@orca> (raw)
In-Reply-To: <20020726201721.B6370@cort.fsmlabs.com>

Hi all,

Below is a rework of Cort Dougan's APM patch of last Thursday and
Friday. As a reminder, the issue is that some laptops, notably Vaios,
don't send notification when the power status changes to AC or to
on-battery. The below patch fixes this such that it always just works.

There are three cases. First, the BIOS doesn't send any notifications;
this is fixed. Second, the BIOS sends notifications. In this case, the
code notes that, and disables the workaround. Third, the BIOS sends
notifications, but somehow we managed to notice the power change before
the BIOS could tell us. This seems highly unlikely, but what the heck,
it could theoretically happen. In that case, we disable the workaround,
and drop the notification that the BIOS generated, as we already sent it
onward up the call chain.

The rework was for a couple of small reasons. First, Cort's patch was
against 2.4.16, and 2.4.18 changed a few things in apm.c. Second, this
pushes the specifics of the workaround down to the get_event() routine,
which exists pretty much solely as an abstraction point between the
actual BIOS call (apm_get_event()) and the event dispatch function
(check_events()). Lastly, I see no need to do dmi matching. The code can
be structured to always do the right thing, so that's what we do.

I'm on the road from Thursday to Monday, and won't be reading email, but
comments are welcome. The patch is pretty darn straight-forward, though.

Please consider for the next -ac patch, and 2.4.20-preX. Actual patch
generated against 2.4.19-rc3-ac5.

Ray Lee

diff -NurX /usr/src/dontdiff linux-2.4.19-rc3-ac5/arch/i386/kernel/apm.c linux-2.4.19-rc3-ac5-apm-fixes/arch/i386/kernel/apm.c
--- linux-2.4.19-rc3-ac5/arch/i386/kernel/apm.c	2002-07-31 11:27:39.000000000 -0700
+++ linux-2.4.19-rc3-ac5-apm-fixes/arch/i386/kernel/apm.c	2002-07-31 11:30:19.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
@@ -1239,17 +1240,46 @@
 	int		error;
 	apm_event_t	event;
 	apm_eventinfo_t	info;
-
+	static u_short	power_event_workaround_enabled = 1;
 	static int notified;
 
 	/* 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) {
+			/* check to see if we jumped the gun and reported a
+			 * power change event that the BIOS would have (and
+			 * just did) on its own. If so, drop the duplicate.
+			 */
+			if (power_event_workaround_enabled)
+				event=get_event();
+			power_event_workaround_enabled = 0;
+		}
 		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_workaround_enabled) {
+		u_short status, bat, life;
+		error = apm_get_power_status(&status, &bat, &life);
+		if (error == APM_SUCCESS) {
+			if ((status ^ last_power_status) & 0xff00) {
+				/* fake an APM_POWER_STATUS_CHANGE event */
+				last_power_status = status;
+				return APM_POWER_STATUS_CHANGE;
+			}
+		} else 
+			power_event_workaround_enabled=0;
+	}
+
 	return 0;
 }
 
@@ -1758,6 +1788,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;


  parent reply	other threads:[~2002-07-31 18:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-26 23:42 [PATCH] fix APM notify of apmd for on-AC/on-battery transitions Ray Lee
2002-07-27  2:17 ` cort
2002-07-29  1:22   ` Ray Lee
2002-07-31 18:33   ` Ray Lee [this message]
2002-07-31 20:10     ` [PATCH] Guarantee APM power status change notifications Bill Davidsen
2002-08-01 14:56       ` Ray Lee
2002-08-01 18:52         ` Bill Davidsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1028140392.1771.66.camel@orca \
    --to=ray-lk@madrabbit.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=cort@fsmlabs.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox