--- arch/i386/kernel/apm.c.orig	Mon Feb 25 19:37:53 2002
+++ arch/i386/kernel/apm.c	Fri Aug 23 00:50:43 2002
@@ -40,6 +40,7 @@
  * Nov 2000, Version 1.14
  * Oct 2001, Version 1.15
  * Jan 2002, Version 1.16
+ * Aug 2002, Version 1.16a
  *
  * History:
  *    0.6b: first version in official kernel, Linux 1.3.46
@@ -177,6 +178,7 @@
  *         CONFIG_APM_CPU_IDLE now just affects the default value of
  *         idle_threshold (sfr).
  *         Change name of kernel apm daemon (as it no longer idles) (sfr).
+ *	1.16a: Add multiple battery support to /proc/apm
  *
  * APM 1.1 Reference:
  *
@@ -416,7 +418,7 @@
 static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
 static struct apm_user *	user_list;
 
-static char			driver_version[] = "1.16";	/* no spaces */
+static char			driver_version[] = "1.16a";	/* no spaces */
 
 /*
  *	APM event names taken from the APM 1.2 specification. These are
@@ -978,7 +980,6 @@
 	return APM_SUCCESS;
 }
 
-#if 0
 static int apm_get_battery_status(u_short which, u_short *status,
 				  u_short *bat, u_short *life, u_short *nbat)
 {
@@ -1005,7 +1006,6 @@
 	*nbat = esi;
 	return APM_SUCCESS;
 }
-#endif
 
 /**
  *	apm_engage_power_management	-	enable PM on a device
@@ -1579,6 +1579,9 @@
 	int		percentage     = -1;
 	int             time_units     = -1;
 	char            *units         = "?";
+	u_short status, bat, life, nbat, tmp;
+	int bpercent, blife, bflags = 0, i;
+	char *bunits;		
 
 	p = buf;
 
@@ -1646,6 +1649,50 @@
 		     percentage,
 		     time_units,
 		     units);
+
+
+	/*
+	 *	Look for details of multiple batteries
+	 *	If it finds any info then it will all a line with
+	 *	just nbat and follow that with one or more lines of
+	 *	bat_index status flags percent life units
+	 *
+	 *	We always check at least 2 batteries and more if moer are indicated.
+	 */
+	apm_get_battery_status(1, &status, &bat, &life, &nbat);
+//	if ((nbat > 1) && (nbat <= APM_MAX_BATTERIES))
+	{
+		int		done_a_battery = 0;
+		if (((p - buf) + nbat * 30 + 10) > length)
+			return p - buf;
+		for (i = 1; i<=((nbat < 2)?2:nbat); i++) {
+			apm_get_battery_status(i, &status, &bat, &life, &tmp);
+			status &= 0xff;
+			if ((bat &0xff) != 0xff)
+				bpercent = bat & 0xff;
+			else
+				bpercent = -1;
+			if (apm_info.connection_version > 0x100) {
+				bflags = (bat >> 8) & 0xff;
+				if (life != 0xffff) {
+					blife = life & 0x7fff;
+					bunits = (life & 0x8000) ? "min" : "sec";
+				} else {
+					if (bpercent == -1)	// don't bother to report if nothing worth knowing.
+						continue;
+					blife = -1;
+					bunits = "?";
+				}
+			}
+
+			if (!done_a_battery) {
+				p += sprintf(p, "%d\n", nbat);
+				done_a_battery++;
+			}
+			p+= sprintf(p, "%d 0x%02x 0x%02x %d%% %d %s\n", i, status, bflags, bpercent, blife, bunits);
+		}
+	}
+
 
 	return p - buf;
 }
