2002-12-30 16:06:43 +03:00
|
|
|
/* $NetBSD: acpi_bat.c,v 1.13 2002/12/30 13:06:43 explorer Exp $ */
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2001 Bill Sommerfeld.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
#if 0
|
2002-03-24 06:46:10 +03:00
|
|
|
#define ACPI_BAT_DEBUG
|
2002-12-30 16:06:43 +03:00
|
|
|
#endif
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI Battery Driver.
|
|
|
|
*
|
|
|
|
* ACPI defines two different battery device interfaces: "Control
|
|
|
|
* Method" batteries, in which AML methods are defined in order to get
|
|
|
|
* battery status and set battery alarm thresholds, and a "Smart
|
|
|
|
* Battery" device, which is an SMbus device accessed through the ACPI
|
|
|
|
* Embedded Controller device.
|
|
|
|
*
|
|
|
|
* This driver is for the "Control Method"-style battery only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2002-12-30 16:06:43 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.13 2002/12/30 13:06:43 explorer Exp $");
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h> /* for hz */
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
|
|
|
|
#include <dev/acpi/acpica.h>
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
|
|
|
2002-08-20 18:07:51 +04:00
|
|
|
#define BAT_WORDS 13
|
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
struct acpibat_softc {
|
|
|
|
struct device sc_dev; /* base device glue */
|
|
|
|
struct acpi_devnode *sc_node; /* our ACPI devnode */
|
|
|
|
int sc_flags; /* see below */
|
|
|
|
struct callout sc_callout; /* XXX temporary polling */
|
2002-12-30 16:06:43 +03:00
|
|
|
int sc_present; /* is battery present? */
|
2002-03-24 06:46:10 +03:00
|
|
|
int sc_status; /* power status */
|
|
|
|
int sc_rate; /* current drain rate */
|
|
|
|
int sc_capacity; /* current capacity */
|
|
|
|
int sc_mv; /* current potential in mV */
|
|
|
|
int sc_design_capacity; /* design capacity */
|
|
|
|
int sc_pred_capacity; /* estimated current max */
|
|
|
|
int sc_warn_capacity; /* warning level */
|
|
|
|
int sc_low_capacity; /* low level */
|
2002-12-30 13:19:59 +03:00
|
|
|
#if 0
|
2002-12-30 12:37:50 +03:00
|
|
|
struct sysmon_power sc_sysmon; /* sysmon hook */
|
2002-12-30 13:19:59 +03:00
|
|
|
#endif
|
2002-08-20 18:07:51 +04:00
|
|
|
ACPI_OBJECT sc_Ret[BAT_WORDS]; /* Return Buffer */
|
2002-03-24 06:46:10 +03:00
|
|
|
};
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
/*
|
|
|
|
* These flags are used to examine the battery device data returned from
|
|
|
|
* the ACPI interface, specifically the "battery status"
|
|
|
|
*/
|
|
|
|
#define ACPIBAT_PWRUNIT_MA 0x00000001 /* mA not mW */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These flags are used to examine the battery charge/discharge/critical
|
|
|
|
* state returned from a get-status command.
|
|
|
|
*/
|
|
|
|
#define ACPIBAT_DISCHARGING 0x00000001 /* battery is discharging */
|
|
|
|
#define ACPIBAT_CHARGING 0x00000002 /* battery is charging */
|
|
|
|
#define ACPIBAT_CRITICAL 0x00000004 /* battery is critical */
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
/*
|
|
|
|
* Flags for battery status from _STA return
|
|
|
|
*/
|
|
|
|
#define ACPIBAT_PRESENT 0x00000010 /* battery present */
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
/*
|
|
|
|
* These flags are used to set internal state in our softc.
|
|
|
|
*/
|
2002-03-24 06:46:10 +03:00
|
|
|
#define ABAT_F_VERBOSE 0x01 /* verbose events */
|
|
|
|
#define ABAT_F_PWRUNIT_MA 0x02 /* mA instead of mW */
|
|
|
|
|
2002-08-02 20:51:48 +04:00
|
|
|
#define ACM_RATEUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"A":"W")
|
|
|
|
#define ACM_CAPUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"Ah":"Wh")
|
|
|
|
#define ACM_SCALE(x) ((x) / 1000), ((x) % 1000)
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
int acpibat_match(struct device *, struct cfdata *, void *);
|
|
|
|
void acpibat_attach(struct device *, struct device *, void *);
|
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(acpibat, sizeof(struct acpibat_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
acpibat_match, acpibat_attach, NULL, NULL);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
static void acpibat_get_status(void *);
|
|
|
|
static void acpibat_get_info(void *);
|
|
|
|
void acpibat_notify_handler(ACPI_HANDLE, UINT32, void *context);
|
|
|
|
static void acpibat_tick(void *);
|
2002-12-30 16:06:43 +03:00
|
|
|
static int acpibat_battery_present(void *);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_match:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `match' routine.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpibat_match(struct device *parent, struct cfdata *match, void *aux)
|
|
|
|
{
|
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
|
|
|
|
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0A") == 0)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_attach:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `attach' routine.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpibat_attach(struct device *parent, struct device *self, void *aux)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = (void *) self;
|
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
printf(": ACPI Battery (Control Method)\n");
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
sc->sc_node = aa->aa_node;
|
|
|
|
|
|
|
|
rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
|
2002-12-30 16:06:43 +03:00
|
|
|
ACPI_DEVICE_NOTIFY,
|
|
|
|
acpibat_notify_handler, sc);
|
2002-03-24 06:46:10 +03:00
|
|
|
if (rv != AE_OK) {
|
|
|
|
printf("%s: unable to register DEVICE NOTIFY handler: %d\n",
|
2002-12-30 16:06:43 +03:00
|
|
|
sc->sc_dev.dv_xname, rv);
|
2002-03-24 06:46:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX See acpibat_notify_handler() */
|
|
|
|
rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
|
2002-12-30 16:06:43 +03:00
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
acpibat_notify_handler, sc);
|
2002-03-24 06:46:10 +03:00
|
|
|
if (rv != AE_OK) {
|
|
|
|
printf("%s: unable to register SYSTEM NOTIFY handler: %d\n",
|
2002-12-30 16:06:43 +03:00
|
|
|
sc->sc_dev.dv_xname, rv);
|
2002-03-24 06:46:10 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-12-30 16:06:43 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
/*
|
|
|
|
* XXX poll battery in the driver for now.
|
|
|
|
* in the future, when we have an API, let userland do this polling
|
|
|
|
*/
|
|
|
|
callout_init(&sc->sc_callout);
|
|
|
|
callout_reset(&sc->sc_callout, 60*hz, acpibat_tick, sc);
|
|
|
|
|
|
|
|
/* Display the current state. */
|
2002-12-30 07:52:13 +03:00
|
|
|
sc->sc_flags = ABAT_F_VERBOSE;
|
2002-03-24 06:46:10 +03:00
|
|
|
acpibat_get_info(sc);
|
|
|
|
acpibat_get_status(sc);
|
|
|
|
|
|
|
|
/*
|
2002-12-30 12:37:50 +03:00
|
|
|
* Hook into sysmon.
|
2002-03-24 06:46:10 +03:00
|
|
|
*/
|
2002-12-30 12:37:50 +03:00
|
|
|
#if 0
|
|
|
|
if (sysmon_power_register(&sc->sc_sysmon))
|
|
|
|
printf("%s: unable to to register with sysmon\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpibat_tick(void *arg)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = arg;
|
|
|
|
callout_reset(&sc->sc_callout, 60*hz, acpibat_tick, arg);
|
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpibat_get_status, sc);
|
|
|
|
}
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
/*
|
|
|
|
* returns 0 for no battery, 1 for present, and -1 on error
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpibat_battery_present(void *arg)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = arg;
|
|
|
|
u_int32_t sta;
|
|
|
|
ACPI_OBJECT *p1;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
|
|
|
buf.Pointer = sc->sc_Ret;
|
|
|
|
buf.Length = sizeof(sc->sc_Ret);
|
|
|
|
|
|
|
|
rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "_STA", NULL, &buf);
|
|
|
|
if (rv != AE_OK) {
|
|
|
|
printf("%s: failed to evaluate _STA: %x\n",
|
|
|
|
sc->sc_dev.dv_xname, rv);
|
|
|
|
sc->sc_present = -1;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
p1 = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
|
|
|
|
if (p1->Type != ACPI_TYPE_INTEGER) {
|
|
|
|
printf("%s: expected INTEGER, got %d\n", sc->sc_dev.dv_xname,
|
|
|
|
p1->Type);
|
|
|
|
sc->sc_present = -1;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (p1->Package.Count < 1) {
|
|
|
|
printf("%s: expected 1 elts, got %d\n",
|
|
|
|
sc->sc_dev.dv_xname, p1->Package.Count);
|
|
|
|
sc->sc_present = -1;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
sta = p1->Integer.Value;
|
|
|
|
|
|
|
|
sc->sc_present = (sta & ACPIBAT_PRESENT) ? 1 : 0;
|
|
|
|
|
|
|
|
return (sc->sc_present);
|
|
|
|
}
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_get_info
|
|
|
|
*
|
|
|
|
* Get, and possibly display, the battery info.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpibat_get_info(void *arg)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = arg;
|
|
|
|
ACPI_OBJECT *p1, *p2;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
(void)acpibat_battery_present(sc);
|
|
|
|
|
|
|
|
if (sc->sc_present != 1) {
|
|
|
|
printf("%s: not present\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BIF", &buf);
|
|
|
|
if (rv != AE_OK) {
|
|
|
|
printf("%s: failed to evaluate _BIF: %x\n",
|
|
|
|
sc->sc_dev.dv_xname, rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p1 = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
|
|
|
printf("%s: expected PACKAGE, got %d\n", sc->sc_dev.dv_xname,
|
|
|
|
p1->Type);
|
|
|
|
goto out;
|
|
|
|
}
|
2002-12-30 07:47:22 +03:00
|
|
|
if (p1->Package.Count < 13) {
|
2002-03-24 06:46:10 +03:00
|
|
|
printf("%s: expected 13 elts, got %d\n",
|
|
|
|
sc->sc_dev.dv_xname, p1->Package.Count);
|
2002-12-30 07:47:22 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
p2 = p1->Package.Elements;
|
2002-12-30 12:37:50 +03:00
|
|
|
if ((p2[0].Integer.Value & ACPIBAT_PWRUNIT_MA) != 0)
|
2002-03-24 06:46:10 +03:00
|
|
|
sc->sc_flags |= ABAT_F_PWRUNIT_MA;
|
|
|
|
|
|
|
|
sc->sc_design_capacity = p2[1].Integer.Value;
|
|
|
|
sc->sc_pred_capacity = p2[2].Integer.Value;
|
|
|
|
sc->sc_warn_capacity = p2[6].Integer.Value;
|
|
|
|
sc->sc_low_capacity = p2[7].Integer.Value;
|
|
|
|
|
|
|
|
printf("%s: %s %s %s %s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
p2[12].String.Pointer, p2[11].String.Pointer,
|
|
|
|
p2[9].String.Pointer, p2[10].String.Pointer);
|
|
|
|
|
2002-08-02 20:51:48 +04:00
|
|
|
printf("%s: Design %d.%03d%s, Predicted %d.%03d%s Warn %d.%03d%s Low %d.%03d%s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ACM_SCALE(sc->sc_design_capacity), ACM_CAPUNIT(sc),
|
|
|
|
ACM_SCALE(sc->sc_pred_capacity), ACM_CAPUNIT(sc),
|
|
|
|
ACM_SCALE(sc->sc_warn_capacity), ACM_CAPUNIT(sc),
|
|
|
|
ACM_SCALE(sc->sc_low_capacity), ACM_CAPUNIT(sc));
|
2002-03-24 06:46:10 +03:00
|
|
|
out:
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_get_status:
|
|
|
|
*
|
|
|
|
* Get, and possibly display, the current battery line status.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpibat_get_status(void *arg)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = arg;
|
|
|
|
ACPI_OBJECT *p1, *p2;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
if (sc->sc_present != 1) {
|
|
|
|
printf("%s: not present\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-20 18:07:51 +04:00
|
|
|
buf.Pointer = sc->sc_Ret;
|
|
|
|
buf.Length = sizeof(sc->sc_Ret);
|
|
|
|
|
|
|
|
rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "_BST", NULL, &buf);
|
2002-03-24 06:46:10 +03:00
|
|
|
if (rv != AE_OK) {
|
2002-08-18 11:45:04 +04:00
|
|
|
printf("bat: failed to evaluate _BST: %x\n", rv);
|
2002-03-24 06:46:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
p1 = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
|
|
|
|
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
|
|
|
printf("bat: expected PACKAGE, got %d\n", p1->Type);
|
2002-08-20 18:07:51 +04:00
|
|
|
return;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
2002-12-30 09:20:02 +03:00
|
|
|
if (p1->Package.Count < 4) {
|
2002-03-24 06:46:10 +03:00
|
|
|
printf("bat: expected 4 elts, got %d\n", p1->Package.Count);
|
2002-12-30 09:20:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-03-24 06:46:10 +03:00
|
|
|
p2 = p1->Package.Elements;
|
|
|
|
|
|
|
|
sc->sc_status = p2[0].Integer.Value;
|
|
|
|
sc->sc_rate = p2[1].Integer.Value;
|
|
|
|
sc->sc_capacity = p2[2].Integer.Value;
|
|
|
|
sc->sc_mv = p2[3].Integer.Value;
|
|
|
|
|
|
|
|
if (sc->sc_flags & ABAT_F_VERBOSE) {
|
2002-12-30 12:37:50 +03:00
|
|
|
|
|
|
|
char *charge, *critical = "";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine charging / discharging state.
|
|
|
|
*/
|
|
|
|
switch (sc->sc_status
|
|
|
|
& (ACPIBAT_DISCHARGING | ACPIBAT_CHARGING)) {
|
|
|
|
case ACPIBAT_DISCHARGING | ACPIBAT_CHARGING:
|
|
|
|
charge = "confused";
|
|
|
|
break;
|
|
|
|
case ACPIBAT_DISCHARGING:
|
|
|
|
charge = "discharging";
|
|
|
|
break;
|
|
|
|
case ACPIBAT_CHARGING:
|
|
|
|
charge = "charging";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
charge = "idle";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the critical bit is set, be loud about it.
|
|
|
|
*/
|
|
|
|
if ((sc->sc_status & ACPIBAT_CRITICAL) != 0)
|
|
|
|
critical = " CRITICAL";
|
|
|
|
|
2002-08-02 20:51:48 +04:00
|
|
|
printf("%s: %s%s: %d.%03dV cap %d.%03d%s (%d%%) rate %d.%03d%s\n",
|
2002-12-30 12:37:50 +03:00
|
|
|
sc->sc_dev.dv_xname, charge, critical,
|
2002-08-02 20:51:48 +04:00
|
|
|
ACM_SCALE(sc->sc_mv),
|
|
|
|
ACM_SCALE(sc->sc_capacity), ACM_CAPUNIT(sc),
|
2002-08-18 11:45:04 +04:00
|
|
|
(sc->sc_design_capacity == 0) ? 0 :
|
|
|
|
(sc->sc_capacity * 100) / sc->sc_design_capacity,
|
2002-08-02 20:51:48 +04:00
|
|
|
ACM_SCALE(sc->sc_rate), ACM_RATEUNIT(sc));
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_notify_handler:
|
|
|
|
*
|
|
|
|
* Callback from ACPI interrupt handler to notify us of an event.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpibat_softc *sc = context;
|
|
|
|
int rv;
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
#ifdef ACPI_BAT_DEBUG
|
|
|
|
printf("%s: received notify message: 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, notify);
|
|
|
|
#endif
|
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
switch (notify) {
|
|
|
|
case ACPI_NOTIFY_BusCheck:
|
2002-12-30 12:37:50 +03:00
|
|
|
break;
|
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
case ACPI_NOTIFY_BatteryInformationChanged:
|
|
|
|
rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
|
2002-12-30 12:37:50 +03:00
|
|
|
acpibat_get_info, sc);
|
2002-03-24 06:46:10 +03:00
|
|
|
if (rv != AE_OK)
|
|
|
|
printf("%s: unable to queue status check: %d\n",
|
2002-12-30 12:37:50 +03:00
|
|
|
sc->sc_dev.dv_xname, rv);
|
2002-12-30 16:06:43 +03:00
|
|
|
break;
|
2002-12-30 12:37:50 +03:00
|
|
|
|
|
|
|
case ACPI_NOTIFY_BatteryStatusChanged:
|
|
|
|
rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
|
|
|
|
acpibat_get_status, sc);
|
|
|
|
if (rv != AE_OK)
|
|
|
|
printf("%s: unable to queue status check: %d\n",
|
|
|
|
sc->sc_dev.dv_xname, rv);
|
2002-03-24 06:46:10 +03:00
|
|
|
break;
|
2002-12-30 12:37:50 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
default:
|
|
|
|
printf("%s: received unknown notify message: 0x%x\n",
|
2002-12-30 12:37:50 +03:00
|
|
|
sc->sc_dev.dv_xname, notify);
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
}
|