Home | History | Annotate | Line # | Download | only in acpi
acpi_bat.c revision 1.13
      1  1.13  explorer /*	$NetBSD: acpi_bat.c,v 1.13 2002/12/30 13:06:43 explorer Exp $	*/
      2   1.1  sommerfe 
      3   1.1  sommerfe /*
      4   1.1  sommerfe  * Copyright 2001 Bill Sommerfeld.
      5   1.1  sommerfe  * All rights reserved.
      6   1.1  sommerfe  *
      7   1.1  sommerfe  * Redistribution and use in source and binary forms, with or without
      8   1.1  sommerfe  * modification, are permitted provided that the following conditions
      9   1.1  sommerfe  * are met:
     10   1.1  sommerfe  * 1. Redistributions of source code must retain the above copyright
     11   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer.
     12   1.1  sommerfe  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  sommerfe  *    documentation and/or other materials provided with the distribution.
     15   1.1  sommerfe  * 3. All advertising materials mentioning features or use of this software
     16   1.1  sommerfe  *    must display the following acknowledgement:
     17   1.1  sommerfe  *	This product includes software developed for the NetBSD Project by
     18   1.1  sommerfe  *	Wasabi Systems, Inc.
     19   1.1  sommerfe  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     20   1.1  sommerfe  *    or promote products derived from this software without specific prior
     21   1.1  sommerfe  *    written permission.
     22   1.1  sommerfe  *
     23   1.1  sommerfe  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     24   1.1  sommerfe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25   1.1  sommerfe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26   1.1  sommerfe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     27   1.1  sommerfe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28   1.1  sommerfe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29   1.1  sommerfe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30   1.1  sommerfe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31   1.1  sommerfe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32   1.1  sommerfe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1  sommerfe  * POSSIBILITY OF SUCH DAMAGE.
     34   1.1  sommerfe  */
     35   1.1  sommerfe 
     36  1.13  explorer #if 0
     37   1.1  sommerfe #define ACPI_BAT_DEBUG
     38  1.13  explorer #endif
     39   1.1  sommerfe 
     40   1.1  sommerfe /*
     41   1.1  sommerfe  * ACPI Battery Driver.
     42   1.1  sommerfe  *
     43   1.1  sommerfe  * ACPI defines two different battery device interfaces: "Control
     44   1.1  sommerfe  * Method" batteries, in which AML methods are defined in order to get
     45   1.1  sommerfe  * battery status and set battery alarm thresholds, and a "Smart
     46   1.1  sommerfe  * Battery" device, which is an SMbus device accessed through the ACPI
     47   1.1  sommerfe  * Embedded Controller device.
     48   1.1  sommerfe  *
     49   1.1  sommerfe  * This driver is for the "Control Method"-style battery only.
     50   1.1  sommerfe  */
     51   1.1  sommerfe 
     52   1.1  sommerfe #include <sys/cdefs.h>
     53  1.13  explorer __KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.13 2002/12/30 13:06:43 explorer Exp $");
     54   1.1  sommerfe 
     55   1.1  sommerfe #include <sys/param.h>
     56   1.1  sommerfe #include <sys/systm.h>
     57   1.1  sommerfe #include <sys/kernel.h>		/* for hz */
     58   1.1  sommerfe #include <sys/device.h>
     59   1.1  sommerfe #include <sys/callout.h>
     60   1.1  sommerfe 
     61   1.1  sommerfe #include <dev/acpi/acpica.h>
     62   1.1  sommerfe #include <dev/acpi/acpireg.h>
     63   1.1  sommerfe #include <dev/acpi/acpivar.h>
     64   1.1  sommerfe 
     65  1.11  explorer #include <dev/sysmon/sysmonvar.h>
     66  1.11  explorer 
     67   1.4  christos #define	BAT_WORDS	13
     68   1.4  christos 
     69   1.1  sommerfe struct acpibat_softc {
     70   1.1  sommerfe 	struct device sc_dev;		/* base device glue */
     71   1.1  sommerfe 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     72   1.1  sommerfe 	int sc_flags;			/* see below */
     73   1.1  sommerfe 	struct callout sc_callout; 	/* XXX temporary polling */
     74  1.13  explorer 	int sc_present;			/* is battery present? */
     75   1.1  sommerfe 	int sc_status;			/* power status */
     76   1.1  sommerfe 	int sc_rate;			/* current drain rate */
     77   1.1  sommerfe 	int sc_capacity;		/* current capacity */
     78   1.1  sommerfe 	int sc_mv;			/* current potential in mV */
     79   1.1  sommerfe 	int sc_design_capacity;		/* design capacity */
     80   1.1  sommerfe 	int sc_pred_capacity;		/* estimated current max */
     81   1.1  sommerfe 	int sc_warn_capacity;		/* warning level */
     82   1.1  sommerfe 	int sc_low_capacity;		/* low level */
     83  1.12     chris #if 0
     84  1.11  explorer 	struct sysmon_power sc_sysmon;	/* sysmon hook */
     85  1.12     chris #endif
     86   1.4  christos 	ACPI_OBJECT sc_Ret[BAT_WORDS];	/* Return Buffer */
     87   1.1  sommerfe };
     88   1.1  sommerfe 
     89  1.11  explorer /*
     90  1.11  explorer  * These flags are used to examine the battery device data returned from
     91  1.11  explorer  * the ACPI interface, specifically the "battery status"
     92  1.11  explorer  */
     93  1.11  explorer #define ACPIBAT_PWRUNIT_MA	0x00000001  /* mA not mW */
     94  1.11  explorer 
     95  1.11  explorer /*
     96  1.11  explorer  * These flags are used to examine the battery charge/discharge/critical
     97  1.11  explorer  * state returned from a get-status command.
     98  1.11  explorer  */
     99  1.11  explorer #define ACPIBAT_DISCHARGING	0x00000001  /* battery is discharging */
    100  1.11  explorer #define ACPIBAT_CHARGING	0x00000002  /* battery is charging */
    101  1.11  explorer #define ACPIBAT_CRITICAL        0x00000004  /* battery is critical */
    102  1.11  explorer 
    103  1.11  explorer /*
    104  1.13  explorer  * Flags for battery status from _STA return
    105  1.13  explorer  */
    106  1.13  explorer #define ACPIBAT_PRESENT		0x00000010  /* battery present */
    107  1.13  explorer 
    108  1.13  explorer /*
    109  1.11  explorer  * These flags are used to set internal state in our softc.
    110  1.11  explorer  */
    111   1.1  sommerfe #define	ABAT_F_VERBOSE		0x01	/* verbose events */
    112   1.1  sommerfe #define ABAT_F_PWRUNIT_MA	0x02 	/* mA instead of mW */
    113   1.1  sommerfe 
    114   1.2  explorer #define ACM_RATEUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"A":"W")
    115   1.2  explorer #define ACM_CAPUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"Ah":"Wh")
    116   1.2  explorer #define ACM_SCALE(x)	((x) / 1000), ((x) % 1000)
    117   1.1  sommerfe 
    118   1.1  sommerfe int	acpibat_match(struct device *, struct cfdata *, void *);
    119   1.1  sommerfe void	acpibat_attach(struct device *, struct device *, void *);
    120   1.1  sommerfe 
    121   1.6   thorpej CFATTACH_DECL(acpibat, sizeof(struct acpibat_softc),
    122   1.7   thorpej     acpibat_match, acpibat_attach, NULL, NULL);
    123   1.1  sommerfe 
    124   1.1  sommerfe static void acpibat_get_status(void *);
    125   1.1  sommerfe static void acpibat_get_info(void *);
    126   1.1  sommerfe void	acpibat_notify_handler(ACPI_HANDLE, UINT32, void *context);
    127   1.1  sommerfe static void acpibat_tick(void *);
    128  1.13  explorer static int acpibat_battery_present(void *);
    129   1.1  sommerfe 
    130   1.1  sommerfe /*
    131   1.1  sommerfe  * acpibat_match:
    132   1.1  sommerfe  *
    133   1.1  sommerfe  *	Autoconfiguration `match' routine.
    134   1.1  sommerfe  */
    135   1.1  sommerfe int
    136   1.1  sommerfe acpibat_match(struct device *parent, struct cfdata *match, void *aux)
    137   1.1  sommerfe {
    138   1.1  sommerfe 	struct acpi_attach_args *aa = aux;
    139   1.1  sommerfe 
    140   1.1  sommerfe 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    141   1.1  sommerfe 		return (0);
    142   1.1  sommerfe 
    143   1.1  sommerfe 	if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0A") == 0)
    144   1.1  sommerfe 		return (1);
    145   1.1  sommerfe 
    146   1.1  sommerfe 	return (0);
    147   1.1  sommerfe }
    148   1.1  sommerfe 
    149   1.1  sommerfe /*
    150   1.1  sommerfe  * acpibat_attach:
    151   1.1  sommerfe  *
    152   1.1  sommerfe  *	Autoconfiguration `attach' routine.
    153   1.1  sommerfe  */
    154   1.1  sommerfe void
    155   1.1  sommerfe acpibat_attach(struct device *parent, struct device *self, void *aux)
    156   1.1  sommerfe {
    157   1.1  sommerfe 	struct acpibat_softc *sc = (void *) self;
    158   1.1  sommerfe 	struct acpi_attach_args *aa = aux;
    159   1.1  sommerfe 	ACPI_STATUS rv;
    160   1.1  sommerfe 
    161  1.11  explorer 	printf(": ACPI Battery (Control Method)\n");
    162   1.1  sommerfe 
    163   1.1  sommerfe 	sc->sc_node = aa->aa_node;
    164   1.1  sommerfe 
    165   1.1  sommerfe 	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
    166  1.13  explorer 				      ACPI_DEVICE_NOTIFY,
    167  1.13  explorer 				      acpibat_notify_handler, sc);
    168   1.1  sommerfe 	if (rv != AE_OK) {
    169   1.1  sommerfe 		printf("%s: unable to register DEVICE NOTIFY handler: %d\n",
    170  1.13  explorer 		       sc->sc_dev.dv_xname, rv);
    171   1.1  sommerfe 		return;
    172   1.1  sommerfe 	}
    173   1.1  sommerfe 
    174   1.1  sommerfe 	/* XXX See acpibat_notify_handler() */
    175   1.1  sommerfe 	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
    176  1.13  explorer 				      ACPI_SYSTEM_NOTIFY,
    177  1.13  explorer 				      acpibat_notify_handler, sc);
    178   1.1  sommerfe 	if (rv != AE_OK) {
    179   1.1  sommerfe 		printf("%s: unable to register SYSTEM NOTIFY handler: %d\n",
    180  1.13  explorer 		       sc->sc_dev.dv_xname, rv);
    181   1.1  sommerfe 		return;
    182   1.1  sommerfe 	}
    183  1.13  explorer 
    184   1.1  sommerfe 	/*
    185   1.1  sommerfe 	 * XXX poll battery in the driver for now.
    186   1.1  sommerfe 	 * in the future, when we have an API, let userland do this polling
    187   1.1  sommerfe 	 */
    188   1.1  sommerfe 	callout_init(&sc->sc_callout);
    189   1.1  sommerfe 	callout_reset(&sc->sc_callout, 60*hz, acpibat_tick, sc);
    190   1.1  sommerfe 
    191   1.1  sommerfe 	/* Display the current state. */
    192   1.9  jmcneill 	sc->sc_flags = ABAT_F_VERBOSE;
    193   1.1  sommerfe 	acpibat_get_info(sc);
    194   1.1  sommerfe 	acpibat_get_status(sc);
    195   1.1  sommerfe 
    196   1.1  sommerfe 	/*
    197  1.11  explorer 	 * Hook into sysmon.
    198   1.1  sommerfe 	 */
    199  1.11  explorer #if 0
    200  1.11  explorer 	if (sysmon_power_register(&sc->sc_sysmon))
    201  1.11  explorer 		printf("%s: unable to to register with sysmon\n",
    202  1.11  explorer 		       sc->sc_dev.dv_xname);
    203  1.11  explorer #endif
    204   1.1  sommerfe }
    205   1.1  sommerfe 
    206   1.1  sommerfe static void
    207   1.1  sommerfe acpibat_tick(void *arg)
    208   1.1  sommerfe {
    209   1.1  sommerfe 	struct acpibat_softc *sc = arg;
    210   1.1  sommerfe 	callout_reset(&sc->sc_callout, 60*hz, acpibat_tick, arg);
    211   1.1  sommerfe 	AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpibat_get_status, sc);
    212   1.1  sommerfe }
    213   1.1  sommerfe 
    214  1.13  explorer /*
    215  1.13  explorer  * returns 0 for no battery, 1 for present, and -1 on error
    216  1.13  explorer  */
    217  1.13  explorer static int
    218  1.13  explorer acpibat_battery_present(void *arg)
    219  1.13  explorer {
    220  1.13  explorer 	struct acpibat_softc *sc = arg;
    221  1.13  explorer 	u_int32_t sta;
    222  1.13  explorer 	ACPI_OBJECT *p1;
    223  1.13  explorer 	ACPI_STATUS rv;
    224  1.13  explorer 	ACPI_BUFFER buf;
    225  1.13  explorer 
    226  1.13  explorer 	buf.Pointer = sc->sc_Ret;
    227  1.13  explorer 	buf.Length = sizeof(sc->sc_Ret);
    228  1.13  explorer 
    229  1.13  explorer 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "_STA", NULL, &buf);
    230  1.13  explorer 	if (rv != AE_OK) {
    231  1.13  explorer 		printf("%s: failed to evaluate _STA: %x\n",
    232  1.13  explorer 		       sc->sc_dev.dv_xname, rv);
    233  1.13  explorer 		sc->sc_present = -1;
    234  1.13  explorer 		return (-1);
    235  1.13  explorer 	}
    236  1.13  explorer 	p1 = (ACPI_OBJECT *)buf.Pointer;
    237  1.13  explorer 
    238  1.13  explorer 	if (p1->Type != ACPI_TYPE_INTEGER) {
    239  1.13  explorer 		printf("%s: expected INTEGER, got %d\n", sc->sc_dev.dv_xname,
    240  1.13  explorer 		       p1->Type);
    241  1.13  explorer 		sc->sc_present = -1;
    242  1.13  explorer 		return (-1);
    243  1.13  explorer 	}
    244  1.13  explorer 	if (p1->Package.Count < 1) {
    245  1.13  explorer 		printf("%s: expected 1 elts, got %d\n",
    246  1.13  explorer 		       sc->sc_dev.dv_xname, p1->Package.Count);
    247  1.13  explorer 		sc->sc_present = -1;
    248  1.13  explorer 		return (-1);
    249  1.13  explorer 	}
    250  1.13  explorer 	sta = p1->Integer.Value;
    251  1.13  explorer 
    252  1.13  explorer 	sc->sc_present = (sta & ACPIBAT_PRESENT) ? 1 : 0;
    253  1.13  explorer 
    254  1.13  explorer 	return (sc->sc_present);
    255  1.13  explorer }
    256   1.1  sommerfe 
    257   1.1  sommerfe /*
    258   1.1  sommerfe  * acpibat_get_info
    259   1.1  sommerfe  *
    260   1.1  sommerfe  * 	Get, and possibly display, the battery info.
    261   1.1  sommerfe  */
    262   1.1  sommerfe 
    263   1.1  sommerfe static void
    264   1.1  sommerfe acpibat_get_info(void *arg)
    265   1.1  sommerfe {
    266   1.1  sommerfe 	struct acpibat_softc *sc = arg;
    267   1.1  sommerfe 	ACPI_OBJECT *p1, *p2;
    268   1.1  sommerfe 	ACPI_STATUS rv;
    269   1.1  sommerfe 	ACPI_BUFFER buf;
    270   1.1  sommerfe 
    271  1.13  explorer 	(void)acpibat_battery_present(sc);
    272  1.13  explorer 
    273  1.13  explorer 	if (sc->sc_present != 1) {
    274  1.13  explorer 		printf("%s: not present\n", sc->sc_dev.dv_xname);
    275  1.13  explorer 		return;
    276  1.13  explorer 	}
    277  1.13  explorer 
    278   1.1  sommerfe 	rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BIF", &buf);
    279   1.1  sommerfe 	if (rv != AE_OK) {
    280   1.1  sommerfe 		printf("%s: failed to evaluate _BIF: %x\n",
    281   1.1  sommerfe 		    sc->sc_dev.dv_xname, rv);
    282   1.1  sommerfe 		return;
    283   1.1  sommerfe 	}
    284   1.1  sommerfe 	p1 = (ACPI_OBJECT *)buf.Pointer;
    285   1.1  sommerfe 	if (p1->Type != ACPI_TYPE_PACKAGE) {
    286   1.1  sommerfe 		printf("%s: expected PACKAGE, got %d\n", sc->sc_dev.dv_xname,
    287   1.1  sommerfe 		    p1->Type);
    288   1.1  sommerfe 		goto out;
    289   1.1  sommerfe 	}
    290   1.8  jmcneill 	if (p1->Package.Count < 13) {
    291   1.1  sommerfe 		printf("%s: expected 13 elts, got %d\n",
    292   1.1  sommerfe 		    sc->sc_dev.dv_xname, p1->Package.Count);
    293   1.8  jmcneill 		goto out;
    294   1.8  jmcneill 	}
    295   1.1  sommerfe 
    296   1.1  sommerfe 	p2 = p1->Package.Elements;
    297  1.11  explorer 	if ((p2[0].Integer.Value & ACPIBAT_PWRUNIT_MA) != 0)
    298   1.1  sommerfe 		sc->sc_flags |= ABAT_F_PWRUNIT_MA;
    299   1.1  sommerfe 
    300   1.1  sommerfe 	sc->sc_design_capacity = p2[1].Integer.Value;
    301   1.1  sommerfe 	sc->sc_pred_capacity = p2[2].Integer.Value;
    302   1.1  sommerfe 	sc->sc_warn_capacity = p2[6].Integer.Value;
    303   1.1  sommerfe 	sc->sc_low_capacity = p2[7].Integer.Value;
    304   1.1  sommerfe 
    305   1.1  sommerfe 	printf("%s: %s %s %s %s\n",
    306   1.1  sommerfe 	    sc->sc_dev.dv_xname,
    307   1.1  sommerfe 	    p2[12].String.Pointer, p2[11].String.Pointer,
    308   1.1  sommerfe 	    p2[9].String.Pointer, p2[10].String.Pointer);
    309   1.1  sommerfe 
    310   1.2  explorer 	printf("%s: Design %d.%03d%s, Predicted %d.%03d%s Warn %d.%03d%s Low %d.%03d%s\n",
    311   1.2  explorer 	       sc->sc_dev.dv_xname,
    312   1.2  explorer 	       ACM_SCALE(sc->sc_design_capacity), ACM_CAPUNIT(sc),
    313   1.2  explorer 	       ACM_SCALE(sc->sc_pred_capacity), ACM_CAPUNIT(sc),
    314   1.2  explorer 	       ACM_SCALE(sc->sc_warn_capacity), ACM_CAPUNIT(sc),
    315   1.2  explorer 	       ACM_SCALE(sc->sc_low_capacity), ACM_CAPUNIT(sc));
    316   1.1  sommerfe out:
    317   1.1  sommerfe 	AcpiOsFree(buf.Pointer);
    318   1.1  sommerfe }
    319   1.1  sommerfe 
    320   1.1  sommerfe /*
    321   1.1  sommerfe  * acpibat_get_status:
    322   1.1  sommerfe  *
    323   1.1  sommerfe  *	Get, and possibly display, the current battery line status.
    324   1.1  sommerfe  */
    325   1.1  sommerfe static void
    326   1.1  sommerfe acpibat_get_status(void *arg)
    327   1.1  sommerfe {
    328   1.1  sommerfe 	struct acpibat_softc *sc = arg;
    329   1.1  sommerfe 	ACPI_OBJECT *p1, *p2;
    330   1.1  sommerfe 	ACPI_STATUS rv;
    331   1.1  sommerfe 	ACPI_BUFFER buf;
    332   1.1  sommerfe 
    333  1.13  explorer 	if (sc->sc_present != 1) {
    334  1.13  explorer 		printf("%s: not present\n", sc->sc_dev.dv_xname);
    335  1.13  explorer 		return;
    336  1.13  explorer 	}
    337  1.13  explorer 
    338   1.4  christos 	buf.Pointer = sc->sc_Ret;
    339   1.4  christos 	buf.Length = sizeof(sc->sc_Ret);
    340   1.4  christos 
    341   1.4  christos 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "_BST", NULL, &buf);
    342   1.1  sommerfe 	if (rv != AE_OK) {
    343   1.3   kanaoka 		printf("bat: failed to evaluate _BST: %x\n", rv);
    344   1.1  sommerfe 		return;
    345   1.1  sommerfe 	}
    346   1.1  sommerfe 	p1 = (ACPI_OBJECT *)buf.Pointer;
    347   1.1  sommerfe 
    348   1.1  sommerfe 	if (p1->Type != ACPI_TYPE_PACKAGE) {
    349   1.1  sommerfe 		printf("bat: expected PACKAGE, got %d\n", p1->Type);
    350   1.4  christos 		return;
    351   1.1  sommerfe 	}
    352  1.10  jmcneill 	if (p1->Package.Count < 4) {
    353   1.1  sommerfe 		printf("bat: expected 4 elts, got %d\n", p1->Package.Count);
    354  1.10  jmcneill 		return;
    355  1.10  jmcneill 	}
    356   1.1  sommerfe 	p2 = p1->Package.Elements;
    357   1.1  sommerfe 
    358   1.1  sommerfe 	sc->sc_status = p2[0].Integer.Value;
    359   1.1  sommerfe 	sc->sc_rate = p2[1].Integer.Value;
    360   1.1  sommerfe 	sc->sc_capacity = p2[2].Integer.Value;
    361   1.1  sommerfe 	sc->sc_mv = p2[3].Integer.Value;
    362   1.1  sommerfe 
    363   1.1  sommerfe 	if (sc->sc_flags & ABAT_F_VERBOSE) {
    364  1.11  explorer 
    365  1.11  explorer 		char *charge, *critical = "";
    366  1.11  explorer 
    367  1.11  explorer 		/*
    368  1.11  explorer 		 * Determine charging / discharging state.
    369  1.11  explorer 		 */
    370  1.11  explorer 		switch (sc->sc_status
    371  1.11  explorer 			& (ACPIBAT_DISCHARGING | ACPIBAT_CHARGING)) {
    372  1.11  explorer 		case ACPIBAT_DISCHARGING | ACPIBAT_CHARGING:
    373  1.11  explorer 			charge = "confused";
    374  1.11  explorer 			break;
    375  1.11  explorer 		case ACPIBAT_DISCHARGING:
    376  1.11  explorer 			charge = "discharging";
    377  1.11  explorer 			break;
    378  1.11  explorer 		case ACPIBAT_CHARGING:
    379  1.11  explorer 			charge = "charging";
    380  1.11  explorer 			break;
    381  1.11  explorer 		default:
    382  1.11  explorer 			charge = "idle";
    383  1.11  explorer 			break;
    384  1.11  explorer 		}
    385  1.11  explorer 
    386  1.11  explorer 		/*
    387  1.11  explorer 		 * If the critical bit is set, be loud about it.
    388  1.11  explorer 		 */
    389  1.11  explorer 		if ((sc->sc_status & ACPIBAT_CRITICAL) != 0)
    390  1.11  explorer 			critical = " CRITICAL";
    391  1.11  explorer 
    392   1.2  explorer 		printf("%s: %s%s: %d.%03dV cap %d.%03d%s (%d%%) rate %d.%03d%s\n",
    393  1.11  explorer 		       sc->sc_dev.dv_xname, charge, critical,
    394   1.2  explorer 		       ACM_SCALE(sc->sc_mv),
    395   1.2  explorer 		       ACM_SCALE(sc->sc_capacity), ACM_CAPUNIT(sc),
    396   1.3   kanaoka 		       (sc->sc_design_capacity == 0) ? 0 :
    397   1.3   kanaoka 			    (sc->sc_capacity * 100) / sc->sc_design_capacity,
    398   1.2  explorer 		       ACM_SCALE(sc->sc_rate), ACM_RATEUNIT(sc));
    399   1.1  sommerfe 	}
    400   1.1  sommerfe }
    401   1.1  sommerfe 
    402   1.1  sommerfe /*
    403   1.1  sommerfe  * acpibat_notify_handler:
    404   1.1  sommerfe  *
    405   1.1  sommerfe  *	Callback from ACPI interrupt handler to notify us of an event.
    406   1.1  sommerfe  */
    407   1.1  sommerfe void
    408   1.1  sommerfe acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
    409   1.1  sommerfe {
    410   1.1  sommerfe 	struct acpibat_softc *sc = context;
    411   1.1  sommerfe 	int rv;
    412   1.1  sommerfe 
    413  1.11  explorer #ifdef ACPI_BAT_DEBUG
    414  1.11  explorer 	printf("%s: received notify message: 0x%x\n",
    415  1.11  explorer 	       sc->sc_dev.dv_xname, notify);
    416  1.11  explorer #endif
    417  1.11  explorer 
    418   1.1  sommerfe 	switch (notify) {
    419   1.1  sommerfe 	case ACPI_NOTIFY_BusCheck:
    420  1.11  explorer 		break;
    421  1.11  explorer 
    422  1.11  explorer 	case ACPI_NOTIFY_BatteryInformationChanged:
    423  1.11  explorer 		rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
    424  1.11  explorer 					     acpibat_get_info, sc);
    425  1.11  explorer 		if (rv != AE_OK)
    426  1.11  explorer 			printf("%s: unable to queue status check: %d\n",
    427  1.11  explorer 			       sc->sc_dev.dv_xname, rv);
    428  1.13  explorer 		break;
    429  1.11  explorer 
    430   1.1  sommerfe 	case ACPI_NOTIFY_BatteryStatusChanged:
    431   1.1  sommerfe 		rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
    432  1.11  explorer 					     acpibat_get_status, sc);
    433   1.1  sommerfe 		if (rv != AE_OK)
    434   1.1  sommerfe 			printf("%s: unable to queue status check: %d\n",
    435  1.11  explorer 			       sc->sc_dev.dv_xname, rv);
    436   1.1  sommerfe 		break;
    437  1.11  explorer 
    438   1.1  sommerfe 	default:
    439   1.1  sommerfe 		printf("%s: received unknown notify message: 0x%x\n",
    440  1.11  explorer 		       sc->sc_dev.dv_xname, notify);
    441   1.1  sommerfe 	}
    442   1.1  sommerfe }
    443