From owner-acpi-jp@jp.freebsd.org  Fri Dec  8 00:10:56 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id AAA57104;
	Fri, 8 Dec 2000 00:10:56 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from kbtfw.kubota.co.jp (firewall-user@kbtfw.kubota.co.jp [133.253.102.202])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id AAA57098;
	Fri, 8 Dec 2000 00:10:54 +0900 (JST)
	(envelope-from haro@tk.kubota.co.jp)
Received: by kbtfw.kubota.co.jp; id AAA11317; Fri, 8 Dec 2000 00:10:53 +0900 (JST)
Received: from unknown(133.253.122.4) by kbtfw.kubota.co.jp via smap (V4.2)
	id xma011300; Fri, 8 Dec 00 00:10:12 +0900
Received: from ktkl129.tk.kubota.co.jp (IDENT:root@kbtgk.eto.kubota.co.jp [133.253.122.3])
	by kbtmk.eto.kubota.co.jp (8.11.1/8.11.1) with ESMTP id eB7FACl99560;
	Fri, 8 Dec 2000 00:10:12 +0900 (JST)
Received: from jkpc15.tk.kubota.co.jp by ktkl129.tk.kubota.co.jp (8.6.13+2.4W/3.4W3-97053016)
	id AAA00756; Fri, 8 Dec 2000 00:08:44 +0900
Received: from localhost (localhost.tk.kubota.co.jp [127.0.0.1])
	by jkpc15.tk.kubota.co.jp (8.11.1/3.7W-02/21/99) with ESMTP id eB7F8aa00783;
	Fri, 8 Dec 2000 00:08:36 +0900 (JST)
To: acpi-jp@jp.freebsd.org, iwasaki@jp.freebsd.org
In-Reply-To: <20001207201322Q.iwasaki@jp.FreeBSD.org>
References: <20001127094651T.haro@tk.kubota.co.jp>
	<20001127163345Y.haro@tk.kubota.co.jp>
	<20001207201322Q.iwasaki@jp.FreeBSD.org>
X-Mailer: Mew version 1.94.1 on Emacs 20.7 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Fri_Dec__8_00:07:12_2000_809)--"
Content-Transfer-Encoding: 7bit
Message-Id: <20001208000836H.haro@tk.kubota.co.jp>
Date: Fri, 08 Dec 2000 00:08:36 +0900
From: Munehiro Matsuda <haro@tk.kubota.co.jp>
X-Dispatcher: imput version 20000228(IM140)
Lines: 233
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 949
Subject: [acpi-jp 949] Re: Some power device driver. 
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: haro@tk.kubota.co.jp

----Next_Part(Fri_Dec__8_00:07:12_2000_809)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
Date: Thu, 07 Dec 2000 20:13:22 +0900
::Remaining battery time seems to be miscalculated?
<snip>
::These are almost double, compare to what APM BIOS said...
<snip>
::
::Changing
::	bat[i].min = 60 * bat[i].bst.cap / bat[i].bst.rate);
::to
::	bat[i].min = (60 * bat[i].bst.cap / bat[i].bst.rate) / units;
::gives me a correct remaining time.

Hmm, it works for me.
I have updated patch for acpibatt, included as acpibatt.patch.
Could you apply the patch and send me output with '-d (debug)' option?

::>  3) Added ioctl API and ACPIIO_ACAD_GET_STATUS ioctl to acpi_acad.c to check
::>     AC-line status.
::This seems OK, but 0x01 is notified for ACAD when I unplugged.
::# It is another Device Check Notification.
::I added new case statement in acpi_acad_notify_handler().

OK, thanks.

::>  4) Added creation of /dev/acpi_acad to etc/MAKEDEV
::
::I think this should be /dev/acpi_acad0 if we intend to support DEVFS.
::/dev/acpi_acad created by MAKEDEV would be hid by mounting DEVFS, so
::better to refer the same device filename as what created by
::make_dev().
::Or, always assuming there is only one AC Adapter on the machine, and
::have hard coded 'acpi_acad' in the device driver too.  This is another
::solution, but I prefer the formar.

'/dev/acpi_acad0' is fine with me.

 Thank you,
   Haro
=------------------------------------------------------------------------------
           _ _    Munehiro (haro) Matsuda
 -|- /_\  |_|_|   Business Incubation Dept., Kubota Corp.
 /|\ |_|  |_|_|   1-3 Nihonbashi-Muromachi 3-Chome
                  Chuo-ku Tokyo 103-8310, Japan
                  Tel: +81-3-3245-3318  Fax: +81-3-3245-3315
                  Email: haro@kubota.co.jp

----Next_Part(Fri_Dec__8_00:07:12_2000_809)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="acpibatt.patch"

Index: acpibatt.c
===================================================================
RCS file: /usr/CVS/src/usr.sbin/acpi/acpibatt/Attic/acpibatt.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 acpibatt.c
--- acpibatt.c	2000/11/27 07:36:47	1.1.2.2
+++ acpibatt.c	2000/11/29 01:08:17
@@ -27,17 +27,17 @@
  *	$FreeBSD$
  */
 
+#include <sys/param.h>
+#include <sys/ioctl.h>
+
+#include <dev/acpica/acpiio.h>
+
 #include <err.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <sys/param.h>
-#include <sys/ioctl.h>
-
-#include <dev/acpica/acpiio.h>
-
 #define ACPIACADDEV	"/dev/acpi_acad"
 #define ACPICMBATDEV	"/dev/acpi_cmbat"
 
@@ -47,7 +47,8 @@
 #define BATT_STAT_MAX		   7
 
 #define BATT_AC_ONLINE		0x08
-#define BATT_INFO_MAX		   9
+
+#define BATT_INFO_MAX		BATT_AC_ONLINE
 
 struct cmbat_info {
 	struct acpi_bif bif;
@@ -59,7 +60,7 @@
 void
 usage(void)
 {
-	fprintf(stderr, "usage: acpibatt [-v]\n");
+	fprintf(stderr, "usage: acpibatt [-vd?]\n");
 	exit(1);
 }
 
@@ -125,6 +126,7 @@
 {
 	int i, c;
 	int stat;
+	int debug;
 	int units;
 	int verbose;
 	int total_cap, total_min;
@@ -138,13 +140,16 @@
 		"critical",
 		"critical and dis-charging",
 		"critical and charging",
-		"not present",
-		NULL
+		"not present"
 	};
+	char *power_units[]= { "mWh", "mAh" };
 
-	verbose = 0;
-	while ((c = getopt(argc, argv, "v")) != -1) {
+	verbose = debug = 0;
+	while ((c = getopt(argc, argv, "vd?")) != -1) {
 		switch (c) {
+		case 'd':
+			debug++;
+			break;
 		case 'v':
 			verbose++;
 			break;
@@ -157,9 +162,6 @@
 	}
 
 	acpi_cmbat_get_units(&units);
-#ifdef DEBUG
-	printf("Number of batteries: %d\n", units);
-#endif
 
 	bat = (struct cmbat_info *)malloc(sizeof(struct cmbat_info) * units);
 	if (bat == NULL) {
@@ -169,26 +171,6 @@
 	stat = valid_rate = valid_units = 0;
 	for (i = 0; i < units; i++) {
 		acpi_cmbat_get_info(i, &bat[i].bif, &bat[i].bst);
-#ifdef DEBUG
-		printf("Battery %d:\n", i);
-		printf("	unit:	%d\n", bat[i].bif.unit);
-		printf("	dcap:	%d\n", bat[i].bif.dcap);
-		printf("	btech:	%d\n", bat[i].bif.btech);
-		printf("	lfcap:	%d\n", bat[i].bif.lfcap);
-		printf("	dvol:	%d\n", bat[i].bif.dvol);
-		printf("	wcap:	%d\n", bat[i].bif.wcap);
-		printf("	lcap:	%d\n", bat[i].bif.lcap);
-		printf("	gra1:	%d\n", bat[i].bif.gra1);
-		printf("	gra2:	%d\n", bat[i].bif.gra2);
-		printf("	model:	%s\n", bat[i].bif.model);
-		printf("	serial:	%s\n", bat[i].bif.serial);
-		printf("	type:	%s\n", bat[i].bif.type);
-		printf("	oeminfo:	%s\n", bat[i].bif.oeminfo);
-		printf("	state:	%d\n", bat[i].bst.state);
-		printf("	rate:	%d\n", bat[i].bst.rate);
-		printf("	cap:	%d\n", bat[i].bst.cap);
-		printf("	volt:	%d\n", bat[i].bst.volt);
-#endif
 
 		/* If battey not installed, state becomes 0xffff */
 		if (bat[i].bst.state >= BATT_STAT_MAX) {
@@ -207,7 +189,7 @@
 			 * XXX Hack to calculate total battery time.
 			 * Systems with two or more battries, they get used
 			 * one by one, thus bst.rate is set only to the one
-			 * in use. For remaning batteries, bst.rate = 0 which
+			 * in use. For remaining batteries bst.rate = 0, which
 			 * makes it impossible to calculate remaining time.
 			 *
 			 * There for we find the largest bst.rate that is
@@ -258,8 +240,11 @@
 	printf("AC Line status: %s\n",
 	    stat & BATT_AC_ONLINE ? "on-line" : "off-line");
 
+	printf("Remaining battery life: ");
 	if (valid_units) {
-		printf("Remaining battery life: %d%%\n", total_cap / valid_units);
+		printf("%d%%\n", total_cap / valid_units);
+	} else {
+		printf("unknown\n");
 	}
 
 	printf("Remaining battery time: ");
@@ -298,7 +283,37 @@
 			printf("\tBattery model : %s\n", bat[i].bif.model);
 			printf("\tBattery serial: %s\n", bat[i].bif.serial);
 			printf("\tBattery type  : %s\n", bat[i].bif.type);
+			printf("\tBattery tech  : %s\n", bat[i].bif.btech > 0 ?
+			    "Secondary (rechargeable)" :
+			    "Primary (non-rechargeable)");
 			printf("\tBattery oeminfo: %s\n", bat[i].bif.oeminfo);
+		}
+
+		/* Debugging informations */
+		if (debug > 0) {
+			char *u = power_units[bat[i].bif.unit & 0x01];
+
+			printf("\t_BIF info\n");
+			printf("\t  unit : %d (%s)\n", bat[i].bif.unit, u);
+			printf("\t  dcap : %5d%s\n", bat[i].bif.dcap, u);
+			printf("\t  lfcap: %5d%s\n", bat[i].bif.lfcap, u);
+			printf("\t  wcap : %5d%s\n", bat[i].bif.wcap, u);
+			printf("\t  lcap : %5d%s\n", bat[i].bif.lcap, u);
+			printf("\t  gra1 : %5d%s\n", bat[i].bif.gra1, u);
+			printf("\t  gra2 : %5d%s\n", bat[i].bif.gra2, u);
+			printf("\t  dvol : %5dmV\n", bat[i].bif.dvol);
+#ifdef DEBUG
+			printf("\t  btech: %d\n", bat[i].bif.btech);
+			printf("\t  model  : %s\n", bat[i].bif.model);
+			printf("\t  serial : %s\n", bat[i].bif.serial);
+			printf("\t  type   : %s\n", bat[i].bif.type);
+			printf("\t  oeminfo: %s\n", bat[i].bif.oeminfo);
+#endif
+			printf("\t_BST info\n");
+			printf("\t  state: %d\n", bat[i].bst.state);
+			printf("\t  rate : %5d%s\n", bat[i].bst.rate, u);
+			printf("\t  cap  : %5d%s\n", bat[i].bst.cap, u);
+			printf("\t  volt : %5dmV\n", bat[i].bst.volt);
 		}
 	}
 	exit(0);

----Next_Part(Fri_Dec__8_00:07:12_2000_809)----
