summaryrefslogtreecommitdiffstats
path: root/sys/dev/acpica
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2003-08-11 15:34:43 +0000
committernjl <njl@FreeBSD.org>2003-08-11 15:34:43 +0000
commit913f59e5bd29583d447d856ebff9f64ecdf9297e (patch)
tree9483237ba1c800d6c52ddd78011cffb5e0e0ec97 /sys/dev/acpica
parent581beee0a85a43275dca02bc412ddbbfecd3f6af (diff)
downloadFreeBSD-src-913f59e5bd29583d447d856ebff9f64ecdf9297e.zip
FreeBSD-src-913f59e5bd29583d447d856ebff9f64ecdf9297e.tar.gz
Style cleanups to match the rest of this directory. For acpi_battery.c,
remove unused includes.
Diffstat (limited to 'sys/dev/acpica')
-rw-r--r--sys/dev/acpica/acpi_acad.c322
-rw-r--r--sys/dev/acpica/acpi_battery.c303
-rw-r--r--sys/dev/acpica/acpi_button.c58
-rw-r--r--sys/dev/acpica/acpi_cmbat.c995
4 files changed, 800 insertions, 878 deletions
diff --git a/sys/dev/acpica/acpi_acad.c b/sys/dev/acpica/acpi_acad.c
index 09bb149..bc3ea38 100644
--- a/sys/dev/acpica/acpi_acad.c
+++ b/sys/dev/acpica/acpi_acad.c
@@ -43,240 +43,230 @@
#include <dev/acpica/acpivar.h>
#include <dev/acpica/acpiio.h>
-/*
- * Hooks for the ACPI CA debugging infrastructure
- */
+/* Hooks for the ACPI CA debugging infrastructure */
#define _COMPONENT ACPI_AC_ADAPTER
ACPI_MODULE_NAME("AC_ADAPTER")
+/* Number of times to retry initialization before giving up. */
+#define ACPI_ACAD_RETRY_MAX 6
+
#define ACPI_DEVICE_CHECK_PNP 0x00
#define ACPI_DEVICE_CHECK_EXISTENCE 0x01
#define ACPI_POWERSOURCE_STAT_CHANGE 0x80
-static void acpi_acad_get_status(void * );
-static void acpi_acad_notify_handler(ACPI_HANDLE , UINT32 ,void *);
-static int acpi_acad_probe(device_t);
-static int acpi_acad_attach(device_t);
-static int acpi_acad_ioctl(u_long, caddr_t, void *);
-static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS);
-static void acpi_acad_init_acline(void *arg);
+struct acpi_acad_softc {
+ int status;
+ int initializing;
+};
+
+static void acpi_acad_get_status(void *);
+static void acpi_acad_notify_handler(ACPI_HANDLE, UINT32, void *);
+static int acpi_acad_probe(device_t);
+static int acpi_acad_attach(device_t);
+static int acpi_acad_ioctl(u_long, caddr_t, void *);
+static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS);
+static void acpi_acad_init_acline(void *arg);
-struct acpi_acad_softc {
- int status;
+static device_method_t acpi_acad_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, acpi_acad_probe),
+ DEVMETHOD(device_attach, acpi_acad_attach),
- int initializing;
+ {0, 0}
+};
+
+static driver_t acpi_acad_driver = {
+ "acpi_acad",
+ acpi_acad_methods,
+ sizeof(struct acpi_acad_softc),
};
+static devclass_t acpi_acad_devclass;
+DRIVER_MODULE(acpi_acad, acpi, acpi_acad_driver, acpi_acad_devclass, 0, 0);
+
static void
acpi_acad_get_status(void *context)
{
- int newstatus;
- device_t dev = context;
- struct acpi_acad_softc *sc = device_get_softc(dev);
- ACPI_HANDLE h = acpi_get_handle(dev);
-
- if (ACPI_FAILURE(acpi_EvaluateInteger(h, "_PSR", &newstatus))) {
- sc->status = -1;
- return;
- }
-
- if (sc->status != newstatus) {
- sc->status = newstatus;
- /* set system power profile based on AC adapter status */
- power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE : POWER_PROFILE_ECONOMY);
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "%s Line\n",(sc->status) ? "On" : "Off");
- }
+ struct acpi_acad_softc *sc;
+ device_t dev;
+ ACPI_HANDLE h;
+ int newstatus;
+
+ dev = context;
+ sc = device_get_softc(dev);
+ h = acpi_get_handle(dev);
+ if (ACPI_FAILURE(acpi_EvaluateInteger(h, "_PSR", &newstatus))) {
+ sc->status = -1;
+ return;
+ }
+
+ if (sc->status != newstatus) {
+ sc->status = newstatus;
+
+ /* Set system power profile based on AC adapter status */
+ power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE :
+ POWER_PROFILE_ECONOMY);
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "%s Line\n", sc->status ? "On" : "Off");
+ }
}
static void
acpi_acad_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
- device_t dev = context;
-
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "Notify %d\n", notify);
-
- switch (notify) {
- case ACPI_DEVICE_CHECK_PNP:
- case ACPI_DEVICE_CHECK_EXISTENCE:
- case ACPI_POWERSOURCE_STAT_CHANGE:
- /*Temporally. It is better to notify policy manager*/
- AcpiOsQueueForExecution(OSD_PRIORITY_LO,
- acpi_acad_get_status,context);
- break;
- default:
- break;
- }
+ device_t dev = context;
+
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "Notify %d\n", notify);
+
+ switch (notify) {
+ case ACPI_DEVICE_CHECK_PNP:
+ case ACPI_DEVICE_CHECK_EXISTENCE:
+ case ACPI_POWERSOURCE_STAT_CHANGE:
+ /* Temporarily. It is better to notify policy manager */
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_get_status, context);
+ break;
+ default:
+ break;
+ }
}
static int
acpi_acad_probe(device_t dev)
{
-
- if ((acpi_get_type(dev) == ACPI_TYPE_DEVICE) &&
+ if (acpi_get_type(dev) == ACPI_TYPE_DEVICE &&
acpi_MatchHid(dev, "ACPI0003")) {
-
- /*
- * Set device description
- */
+
device_set_desc(dev, "AC adapter");
- return(0);
+ return (0);
}
- return(ENXIO);
+ return (ENXIO);
}
static int
acpi_acad_attach(device_t dev)
{
- int error;
- struct acpi_acad_softc *sc;
- struct acpi_softc *acpi_sc;
-
- ACPI_HANDLE handle = acpi_get_handle(dev);
- AcpiInstallNotifyHandler(handle,
- ACPI_DEVICE_NOTIFY,
- acpi_acad_notify_handler, dev);
- /*Installing system notify is not so good*/
- AcpiInstallNotifyHandler(handle,
- ACPI_SYSTEM_NOTIFY,
- acpi_acad_notify_handler, dev);
-
- if ((sc = device_get_softc(dev)) == NULL) {
- return (ENXIO);
- }
- if ((error = acpi_register_ioctl(ACPIIO_ACAD_GET_STATUS,
- acpi_acad_ioctl, dev)) != 0) {
- return (error);
- }
-
- if (device_get_unit(dev) == 0) {
- acpi_sc = acpi_device_get_parent_softc(dev);
- SYSCTL_ADD_PROC(&acpi_sc->acpi_sysctl_ctx,
+ struct acpi_acad_softc *sc;
+ struct acpi_softc *acpi_sc;
+ ACPI_HANDLE handle;
+ int error;
+
+ handle = acpi_get_handle(dev);
+ AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
+ acpi_acad_notify_handler, dev);
+ /* XXX Installing system notify is not so good */
+ AcpiInstallNotifyHandler(handle, ACPI_SYSTEM_NOTIFY,
+ acpi_acad_notify_handler, dev);
+
+ if ((sc = device_get_softc(dev)) == NULL)
+ return (ENXIO);
+
+ error = acpi_register_ioctl(ACPIIO_ACAD_GET_STATUS, acpi_acad_ioctl, dev);
+ if (error != 0)
+ return (error);
+
+ if (device_get_unit(dev) == 0) {
+ acpi_sc = acpi_device_get_parent_softc(dev);
+ SYSCTL_ADD_PROC(&acpi_sc->acpi_sysctl_ctx,
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD,
&sc->status, 0, acpi_acad_sysctl, "I", "");
- }
+ }
- /* Get initial status after whole system is up. */
- sc->status = -1;
- sc->initializing = 0;
+ /* Get initial status after whole system is up. */
+ sc->status = -1;
+ sc->initializing = 0;
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_init_acline, dev);
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_init_acline, dev);
- return(0);
+ return (0);
}
-static device_method_t acpi_acad_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, acpi_acad_probe),
- DEVMETHOD(device_attach, acpi_acad_attach),
-
- {0, 0}
-};
-
-static driver_t acpi_acad_driver = {
- "acpi_acad",
- acpi_acad_methods,
- sizeof(struct acpi_acad_softc),
-};
-
-static devclass_t acpi_acad_devclass;
-DRIVER_MODULE(acpi_acad,acpi,acpi_acad_driver,acpi_acad_devclass,0,0);
-
static int
acpi_acad_ioctl(u_long cmd, caddr_t addr, void *arg)
{
- device_t dev;
- struct acpi_acad_softc *sc;
-
- dev = (device_t)arg;
- if ((sc = device_get_softc(dev)) == NULL) {
- return(ENXIO);
- }
-
- /*
- * No security check required: information retrieval only. If
- * new functions are added here, a check might be required.
- */
-
- switch (cmd) {
- case ACPIIO_ACAD_GET_STATUS:
- acpi_acad_get_status(dev);
- *(int *)addr = sc->status;
- break;
- }
-
- return(0);
+ struct acpi_acad_softc *sc;
+ device_t dev;
+
+ dev = (device_t)arg;
+ if ((sc = device_get_softc(dev)) == NULL)
+ return(ENXIO);
+
+ /*
+ * No security check required: information retrieval only. If
+ * new functions are added here, a check might be required.
+ */
+ switch (cmd) {
+ case ACPIIO_ACAD_GET_STATUS:
+ acpi_acad_get_status(dev);
+ *(int *)addr = sc->status;
+ break;
+ default:
+ break;
+ }
+
+ return (0);
}
static int
acpi_acad_sysctl(SYSCTL_HANDLER_ARGS)
{
- int val;
- int error;
+ int val, error;
- if (acpi_acad_get_acline(&val)) {
- return (ENXIO);
- }
+ if (acpi_acad_get_acline(&val) != 0)
+ return (ENXIO);
- val = *(u_int *)oidp->oid_arg1;
- error = sysctl_handle_int(oidp, &val, 0, req);
- return (error);
+ val = *(u_int *)oidp->oid_arg1;
+ error = sysctl_handle_int(oidp, &val, 0, req);
+ return (error);
}
static void
acpi_acad_init_acline(void *arg)
{
- int retry;
- int status;
- device_t dev = (device_t)arg;
- struct acpi_acad_softc *sc = device_get_softc(dev);
-#define ACPI_ACAD_RETRY_MAX 6
-
- if (sc->initializing) {
- return;
- }
+ struct acpi_acad_softc *sc;
+ device_t dev;
+ int retry, status;
- sc->initializing = 1;
-
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "acline initialization start\n");
+ dev = (device_t)arg;
+ sc = device_get_softc(dev);
+ if (sc->initializing)
+ return;
- status = 0;
- for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
- acpi_acad_get_status(dev);
- if (status != sc->status)
- break;
- }
+ sc->initializing = 1;
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "acline initialization start\n");
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "acline initialization done, tried %d times\n", retry+1);
+ status = 0;
+ for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
+ acpi_acad_get_status(dev);
+ if (status != sc->status)
+ break;
+ }
- sc->initializing = 0;
+ sc->initializing = 0;
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "acline initialization done, tried %d times\n", retry+1);
}
/*
* Public interfaces.
*/
-
int
acpi_acad_get_acline(int *status)
{
- device_t dev;
- struct acpi_acad_softc *sc;
+ struct acpi_acad_softc *sc;
+ device_t dev;
- if ((dev = devclass_get_device(acpi_acad_devclass, 0)) == NULL) {
- return (ENXIO);
- }
+ dev = devclass_get_device(acpi_acad_devclass, 0);
+ if (dev == NULL)
+ return (ENXIO);
+ sc = device_get_softc(dev);
+ if (sc == NULL)
+ return (ENXIO);
- if ((sc = device_get_softc(dev)) == NULL) {
- return (ENXIO);
- }
+ acpi_acad_get_status(dev);
+ *status = sc->status;
- acpi_acad_get_status(dev);
- *status = sc->status;
-
- return (0);
+ return (0);
}
-
diff --git a/sys/dev/acpica/acpi_battery.c b/sys/dev/acpica/acpi_battery.c
index e26aee1..51af72d 100644
--- a/sys/dev/acpica/acpi_battery.c
+++ b/sys/dev/acpica/acpi_battery.c
@@ -26,36 +26,23 @@
* $FreeBSD$
*/
-#include "opt_acpi.h" /* XXX trim includes */
+#include "opt_acpi.h"
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/bus.h>
-#include <sys/conf.h>
#include <sys/ioccom.h>
-#include <sys/reboot.h>
#include <sys/sysctl.h>
-#include <sys/ctype.h>
-
-#include <machine/clock.h>
-
-#include <machine/resource.h>
#include "acpi.h"
-
#include <dev/acpica/acpivar.h>
#include <dev/acpica/acpiio.h>
MALLOC_DEFINE(M_ACPIBATT, "acpibatt", "ACPI generic battery data");
-/*
- * ACPI Battery Abstruction Layer.
- */
-
struct acpi_batteries {
- TAILQ_ENTRY(acpi_batteries) link;
- struct acpi_battdesc battdesc;
+ TAILQ_ENTRY(acpi_batteries) link;
+ struct acpi_battdesc battdesc;
};
static TAILQ_HEAD(,acpi_batteries) acpi_batteries;
@@ -67,200 +54,190 @@ static struct acpi_battinfo acpi_battery_battinfo;
int
acpi_battery_get_units(void)
{
-
- return (acpi_batteries_units);
+ return (acpi_batteries_units);
}
int
acpi_battery_get_battdesc(int logical_unit, struct acpi_battdesc *battdesc)
{
- int i;
- struct acpi_batteries *bp;
+ struct acpi_batteries *bp;
+ int i;
- if (logical_unit < 0 || logical_unit >= acpi_batteries_units) {
- return (ENXIO);
- }
+ if (logical_unit < 0 || logical_unit >= acpi_batteries_units)
+ return (ENXIO);
- i = 0;
- TAILQ_FOREACH(bp, &acpi_batteries, link) {
- if (logical_unit == i) {
- battdesc->type = bp->battdesc.type;
- battdesc->phys_unit = bp->battdesc.phys_unit;
- return (0);
- }
- i++;
+ i = 0;
+ TAILQ_FOREACH(bp, &acpi_batteries, link) {
+ if (logical_unit == i) {
+ battdesc->type = bp->battdesc.type;
+ battdesc->phys_unit = bp->battdesc.phys_unit;
+ return (0);
}
+ i++;
+ }
- return (ENXIO);
+ return (ENXIO);
}
int
acpi_battery_get_battinfo(int unit, struct acpi_battinfo *battinfo)
{
- int error;
- struct acpi_battdesc battdesc;
-
- error = 0;
- if (unit == -1) {
- error = acpi_cmbat_get_battinfo(-1, battinfo);
- goto out;
- } else {
- if ((error = acpi_battery_get_battdesc(unit, &battdesc)) != 0) {
- goto out;
- }
- switch (battdesc.type) {
- case ACPI_BATT_TYPE_CMBAT:
- error = acpi_cmbat_get_battinfo(battdesc.phys_unit,
- battinfo);
- break;
- default:
- error = ENXIO;
- break;
- }
+ struct acpi_battdesc battdesc;
+ int error;
+
+ error = 0;
+ if (unit == -1) {
+ error = acpi_cmbat_get_battinfo(-1, battinfo);
+ goto out;
+ } else {
+ error = acpi_battery_get_battdesc(unit, &battdesc);
+ if (error != 0)
+ goto out;
+
+ switch (battdesc.type) {
+ case ACPI_BATT_TYPE_CMBAT:
+ error = acpi_cmbat_get_battinfo(battdesc.phys_unit, battinfo);
+ break;
+ default:
+ error = ENXIO;
+ break;
}
+ }
+
out:
- return (error);
+ return (error);
}
int
acpi_battery_get_info_expire(void)
{
-
- return (acpi_battery_info_expire);
+ return (acpi_battery_info_expire);
}
static int
acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg)
{
- int error;
- int logical_unit;
- union acpi_battery_ioctl_arg *ioctl_arg;
-
- ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
- error = 0;
-
- /*
- * No security check required: information retrieval only. If
- * new functions are added here, a check might be required.
- */
-
- switch (cmd) {
- case ACPIIO_BATT_GET_UNITS:
- *(int *)addr = acpi_battery_get_units();
- break;
-
- case ACPIIO_BATT_GET_BATTDESC:
- logical_unit = ioctl_arg->unit;
- error = acpi_battery_get_battdesc(logical_unit, &ioctl_arg->battdesc);
- break;
-
- case ACPIIO_BATT_GET_BATTINFO:
- logical_unit = ioctl_arg->unit;
- error = acpi_battery_get_battinfo(logical_unit,
- &ioctl_arg->battinfo);
- break;
-
- default:
- error = EINVAL;
- break;
- }
-
- return (error);
+ union acpi_battery_ioctl_arg *ioctl_arg;
+ int error, logical_unit;
+
+ ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
+ error = 0;
+
+ /*
+ * No security check required: information retrieval only. If
+ * new functions are added here, a check might be required.
+ */
+ switch (cmd) {
+ case ACPIIO_BATT_GET_UNITS:
+ *(int *)addr = acpi_battery_get_units();
+ break;
+ case ACPIIO_BATT_GET_BATTDESC:
+ logical_unit = ioctl_arg->unit;
+ error = acpi_battery_get_battdesc(logical_unit, &ioctl_arg->battdesc);
+ break;
+ case ACPIIO_BATT_GET_BATTINFO:
+ logical_unit = ioctl_arg->unit;
+ error = acpi_battery_get_battinfo(logical_unit, &ioctl_arg->battinfo);
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return (error);
}
static int
acpi_battery_sysctl(SYSCTL_HANDLER_ARGS)
{
- int val;
- int error;
+ int val, error;
- acpi_battery_get_battinfo(-1, &acpi_battery_battinfo);
- val = *(u_int *)oidp->oid_arg1;
- error = sysctl_handle_int(oidp, &val, 0, req);
- return (error);
+ acpi_battery_get_battinfo(-1, &acpi_battery_battinfo);
+ val = *(u_int *)oidp->oid_arg1;
+ error = sysctl_handle_int(oidp, &val, 0, req);
+ return (error);
}
static int
acpi_battery_init(void)
{
- device_t dev;
- struct acpi_softc *sc;
- int error;
-
- if ((dev = devclass_get_device(devclass_find("acpi"), 0)) == NULL) {
- return (ENXIO);
- }
- if ((sc = device_get_softc(dev)) == NULL) {
- return (ENXIO);
- }
-
- error = 0;
+ struct acpi_softc *sc;
+ device_t dev;
+ int error;
- TAILQ_INIT(&acpi_batteries);
- acpi_batteries_initted = 1;
-
- if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS,
- acpi_battery_ioctl, NULL)) != 0) {
- return (error);
- }
- if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTDESC,
- acpi_battery_ioctl, NULL)) != 0) {
- return (error);
- }
- if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO,
- acpi_battery_ioctl, NULL)) != 0) {
- return (error);
- }
+ dev = devclass_get_device(devclass_find("acpi"), 0);
+ if (dev == NULL)
+ return (ENXIO);
+ sc = device_get_softc(dev);
+ if (sc == NULL)
+ return (ENXIO);
- sysctl_ctx_init(&sc->acpi_battery_sysctl_ctx);
- sc->acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
- OID_AUTO, "battery", CTLFLAG_RD, 0, "");
- SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
- OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
- &acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
- SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
- OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
- &acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
- SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
- OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
- &acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
- SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
- OID_AUTO, "units", CTLFLAG_RD, &acpi_batteries_units, 0, "");
- SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
- SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
- OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
- &acpi_battery_info_expire, 0, "");
+ error = 0;
+ TAILQ_INIT(&acpi_batteries);
+ acpi_batteries_initted = 1;
+ error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS, acpi_battery_ioctl,
+ NULL);
+ if (error != 0)
+ return (error);
+ error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTDESC, acpi_battery_ioctl,
+ NULL);
+ if (error != 0)
return (error);
+ error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO, acpi_battery_ioctl,
+ NULL);
+ if (error != 0)
+ return (error);
+
+ sysctl_ctx_init(&sc->acpi_battery_sysctl_ctx);
+ sc->acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
+ OID_AUTO, "battery", CTLFLAG_RD, 0, "");
+ SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
+ OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
+ &acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
+ SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
+ OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
+ &acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
+ SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
+ OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
+ &acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
+ SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
+ OID_AUTO, "units", CTLFLAG_RD, &acpi_batteries_units, 0, "");
+ SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
+ OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
+ &acpi_battery_info_expire, 0, "");
+
+ return (error);
}
int
acpi_battery_register(int type, int phys_unit)
{
- int error;
- struct acpi_batteries *bp;
-
- error = 0;
- if ((bp = malloc(sizeof(*bp), M_ACPIBATT, M_NOWAIT)) == NULL) {
- return(ENOMEM);
- }
-
- bp->battdesc.type = type;
- bp->battdesc.phys_unit = phys_unit;
- if (acpi_batteries_initted == 0) {
- if ((error = acpi_battery_init()) != 0) {
- free(bp, M_ACPIBATT);
- return(error);
- }
+ struct acpi_batteries *bp;
+ int error;
+
+ error = 0;
+ bp = malloc(sizeof(*bp), M_ACPIBATT, M_NOWAIT);
+ if (bp == NULL)
+ return (ENOMEM);
+
+ bp->battdesc.type = type;
+ bp->battdesc.phys_unit = phys_unit;
+ if (acpi_batteries_initted == 0) {
+ if ((error = acpi_battery_init()) != 0) {
+ free(bp, M_ACPIBATT);
+ return (error);
}
+ }
- TAILQ_INSERT_TAIL(&acpi_batteries, bp, link);
- acpi_batteries_units++;
+ TAILQ_INSERT_TAIL(&acpi_batteries, bp, link);
+ acpi_batteries_units++;
- return(0);
+ return (0);
}
diff --git a/sys/dev/acpica/acpi_button.c b/sys/dev/acpica/acpi_button.c
index f1a9221..f8db68b 100644
--- a/sys/dev/acpica/acpi_button.c
+++ b/sys/dev/acpica/acpi_button.c
@@ -34,28 +34,29 @@
#include <sys/bus.h>
#include "acpi.h"
-
#include <dev/acpica/acpivar.h>
-/*
- * Hooks for the ACPI CA debugging infrastructure
- */
+/* Hooks for the ACPI CA debugging infrastructure */
#define _COMPONENT ACPI_BUTTON
ACPI_MODULE_NAME("BUTTON")
struct acpi_button_softc {
device_t button_dev;
ACPI_HANDLE button_handle;
-#define ACPI_POWER_BUTTON 0
-#define ACPI_SLEEP_BUTTON 1
boolean_t button_type; /* Power or Sleep Button */
+#define ACPI_POWER_BUTTON 0
+#define ACPI_SLEEP_BUTTON 1
};
+#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP 0x80
+#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP 0x02
+
static int acpi_button_probe(device_t dev);
static int acpi_button_attach(device_t dev);
static int acpi_button_suspend(device_t dev);
static int acpi_button_resume(device_t dev);
-static void acpi_button_notify_handler(ACPI_HANDLE h,UINT32 notify, void *context);
+static void acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify,
+ void *context);
static void acpi_button_notify_pressed_for_sleep(void *arg);
static void acpi_button_notify_pressed_for_wakeup(void *arg);
@@ -77,7 +78,8 @@ static driver_t acpi_button_driver = {
};
static devclass_t acpi_button_devclass;
-DRIVER_MODULE(acpi_button, acpi, acpi_button_driver, acpi_button_devclass, 0, 0);
+DRIVER_MODULE(acpi_button, acpi, acpi_button_driver, acpi_button_devclass,
+ 0, 0);
static int
acpi_button_probe(device_t dev)
@@ -90,16 +92,16 @@ acpi_button_probe(device_t dev)
if (acpi_MatchHid(dev, "PNP0C0C")) {
device_set_desc(dev, "Power Button");
sc->button_type = ACPI_POWER_BUTTON;
- return(0);
+ return (0);
}
if (acpi_MatchHid(dev, "PNP0C0E")) {
device_set_desc(dev, "Sleep Button");
sc->button_type = ACPI_SLEEP_BUTTON;
- return(0);
+ return (0);
}
}
}
- return(ENXIO);
+ return (ENXIO);
}
static int
@@ -114,13 +116,15 @@ acpi_button_attach(device_t dev)
sc->button_dev = dev;
sc->button_handle = acpi_get_handle(dev);
- if (ACPI_FAILURE(status = AcpiInstallNotifyHandler(sc->button_handle, ACPI_DEVICE_NOTIFY,
- acpi_button_notify_handler, sc))) {
- device_printf(sc->button_dev, "couldn't install Notify handler - %s\n", AcpiFormatException(status));
- return_VALUE(ENXIO);
+ status = AcpiInstallNotifyHandler(sc->button_handle, ACPI_DEVICE_NOTIFY,
+ acpi_button_notify_handler, sc);
+ if (ACPI_FAILURE(status)) {
+ device_printf(sc->button_dev, "couldn't install Notify handler - %s\n",
+ AcpiFormatException(status));
+ return_VALUE (ENXIO);
}
acpi_device_enable_wake_capability(sc->button_handle, 1);
- return_VALUE(0);
+ return_VALUE (0);
}
static int
@@ -136,7 +140,6 @@ acpi_button_suspend(device_t dev)
static int
acpi_button_resume(device_t dev)
{
-
return (0);
}
@@ -150,9 +153,8 @@ acpi_button_notify_pressed_for_sleep(void *arg)
sc = (struct acpi_button_softc *)arg;
acpi_sc = acpi_device_get_parent_softc(sc->button_dev);
- if (acpi_sc == NULL) {
+ if (acpi_sc == NULL)
return_VOID;
- }
switch (sc->button_type) {
case ACPI_POWER_BUTTON:
@@ -166,7 +168,6 @@ acpi_button_notify_pressed_for_sleep(void *arg)
default:
break; /* unknown button type */
}
- return_VOID;
}
static void
@@ -179,9 +180,8 @@ acpi_button_notify_pressed_for_wakeup(void *arg)
sc = (struct acpi_button_softc *)arg;
acpi_sc = acpi_device_get_parent_softc(sc->button_dev);
- if (acpi_sc == NULL) {
+ if (acpi_sc == NULL)
return_VOID;
- }
switch (sc->button_type) {
case ACPI_POWER_BUTTON:
@@ -195,13 +195,8 @@ acpi_button_notify_pressed_for_wakeup(void *arg)
default:
break; /* unknown button type */
}
- return_VOID;
}
-/* XXX maybe not here */
-#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP 0x80
-#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP 0x02
-
static void
acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
@@ -211,15 +206,14 @@ acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
switch (notify) {
case ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP:
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_pressed_for_sleep, sc);
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO,
+ acpi_button_notify_pressed_for_sleep, sc);
break;
case ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP:
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_pressed_for_wakeup, sc);
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO,
+ acpi_button_notify_pressed_for_wakeup, sc);
break;
default:
break; /* unknown notification value */
}
- return_VOID;
}
-
-
diff --git a/sys/dev/acpica/acpi_cmbat.c b/sys/dev/acpica/acpi_cmbat.c
index 1cfd584..5fac197 100644
--- a/sys/dev/acpica/acpi_cmbat.c
+++ b/sys/dev/acpica/acpi_cmbat.c
@@ -33,354 +33,338 @@
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/ioccom.h>
-#include <sys/conf.h>
#include <machine/bus.h>
-#include <machine/resource.h>
#include <sys/rman.h>
#include <sys/malloc.h>
-#include "acpi.h"
-
+#include "acpi.h"
#include <dev/acpica/acpivar.h>
#include <dev/acpica/acpiio.h>
MALLOC_DEFINE(M_ACPICMBAT, "acpicmbat", "ACPI control method battery data");
+/* Number of times to retry initialization before giving up. */
+#define ACPI_CMBAT_RETRY_MAX 6
+
+/* Check the battery once a minute. */
#define CMBAT_POLLRATE (60 * hz)
-/*
- * Hooks for the ACPI CA debugging infrastructure
- */
+/* Hooks for the ACPI CA debugging infrastructure */
#define _COMPONENT ACPI_BATTERY
ACPI_MODULE_NAME("BATTERY")
#define ACPI_BATTERY_BST_CHANGE 0x80
#define ACPI_BATTERY_BIF_CHANGE 0x81
-#define PKG_GETINT(res, tmp, idx, dest, label) do { \
- tmp = &res->Package.Elements[idx]; \
- if (tmp == NULL) { \
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), \
+#define PKG_GETINT(res, tmp, idx, dest, label) do { \
+ tmp = &res->Package.Elements[idx]; \
+ if (tmp == NULL) { \
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), \
"%s: PKG_GETINT error, idx = %d\n.", __func__, idx); \
- goto label; \
- } \
- if (tmp->Type != ACPI_TYPE_INTEGER) \
- goto label; \
- dest = tmp->Integer.Value; \
+ goto label; \
+ } \
+ if (tmp->Type != ACPI_TYPE_INTEGER) \
+ goto label; \
+ dest = tmp->Integer.Value; \
} while (0)
-#define PKG_GETSTR(res, tmp, idx, dest, size, label) do { \
- size_t length; \
- length = size; \
- tmp = &res->Package.Elements[idx]; \
- if (tmp == NULL) { \
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), \
+#define PKG_GETSTR(res, tmp, idx, dest, size, label) do { \
+ size_t length; \
+ length = size; \
+ tmp = &res->Package.Elements[idx]; \
+ if (tmp == NULL) { \
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), \
"%s: PKG_GETSTR error, idx = %d\n.", __func__, idx); \
- goto label; \
- } \
- bzero(dest, sizeof(dest)); \
- switch (tmp->Type) { \
- case ACPI_TYPE_STRING: \
- if (tmp->String.Length < length) { \
- length = tmp->String.Length; \
- } \
- strncpy(dest, tmp->String.Pointer, length); \
- break; \
- case ACPI_TYPE_BUFFER: \
- if (tmp->Buffer.Length < length) { \
- length = tmp->Buffer.Length; \
- } \
- strncpy(dest, tmp->Buffer.Pointer, length); \
- break; \
- default: \
- goto label; \
- } \
- dest[sizeof(dest)-1] = '\0'; \
+ goto label; \
+ } \
+ bzero(dest, sizeof(dest)); \
+ switch (tmp->Type) { \
+ case ACPI_TYPE_STRING: \
+ if (tmp->String.Length < length) \
+ length = tmp->String.Length; \
+ strncpy(dest, tmp->String.Pointer, length); \
+ break; \
+ case ACPI_TYPE_BUFFER: \
+ if (tmp->Buffer.Length < length) \
+ length = tmp->Buffer.Length; \
+ strncpy(dest, tmp->Buffer.Pointer, length); \
+ break; \
+ default: \
+ goto label; \
+ } \
+ dest[sizeof(dest)-1] = '\0'; \
} while (0)
struct acpi_cmbat_softc {
- device_t dev;
-
- struct acpi_bif bif;
- struct acpi_bst bst;
- struct timespec bif_lastupdated;
- struct timespec bst_lastupdated;
- int bif_updating;
- int bst_updating;
-
- int present;
- int cap;
- int min;
- int full_charge_time;
- int initializing;
+ device_t dev;
+
+ struct acpi_bif bif;
+ struct acpi_bst bst;
+ struct timespec bif_lastupdated;
+ struct timespec bst_lastupdated;
+ int bif_updating;
+ int bst_updating;
+
+ int present;
+ int cap;
+ int min;
+ int full_charge_time;
+ int initializing;
};
-static struct timespec acpi_cmbat_info_lastupdated;
-
-/* XXX: devclass_get_maxunit() don't give us the current allocated units... */
-static int acpi_cmbat_units = 0;
-
-static int acpi_cmbat_info_expired(struct timespec *);
-static void acpi_cmbat_info_updated(struct timespec *);
-static void acpi_cmbat_get_bst(void *);
-static void acpi_cmbat_get_bif(void *);
-static void acpi_cmbat_notify_handler(ACPI_HANDLE, UINT32, void *);
-static int acpi_cmbat_probe(device_t);
-static int acpi_cmbat_attach(device_t);
-static int acpi_cmbat_resume(device_t);
-static int acpi_cmbat_ioctl(u_long, caddr_t, void *);
-static int acpi_cmbat_is_bst_valid(struct acpi_bst*);
-static int acpi_cmbat_is_bif_valid(struct acpi_bif*);
-static int acpi_cmbat_get_total_battinfo(struct acpi_battinfo *);
-static void acpi_cmbat_init_battery(void *);
+static struct timespec acpi_cmbat_info_lastupdated;
+
+/* XXX: devclass_get_maxunit() don't give us the current allocated units. */
+static int acpi_cmbat_units = 0;
+
+static int acpi_cmbat_info_expired(struct timespec *);
+static void acpi_cmbat_info_updated(struct timespec *);
+static void acpi_cmbat_get_bst(void *);
+static void acpi_cmbat_get_bif(void *);
+static void acpi_cmbat_notify_handler(ACPI_HANDLE, UINT32, void *);
+static int acpi_cmbat_probe(device_t);
+static int acpi_cmbat_attach(device_t);
+static int acpi_cmbat_resume(device_t);
+static int acpi_cmbat_ioctl(u_long, caddr_t, void *);
+static int acpi_cmbat_is_bst_valid(struct acpi_bst*);
+static int acpi_cmbat_is_bif_valid(struct acpi_bif*);
+static int acpi_cmbat_get_total_battinfo(struct acpi_battinfo *);
+static void acpi_cmbat_init_battery(void *);
static __inline int
acpi_cmbat_info_expired(struct timespec *lastupdated)
{
- struct timespec curtime;
-
- if (lastupdated == NULL) {
- return (1);
- }
+ struct timespec curtime;
- if (!timespecisset(lastupdated)) {
- return (1);
- }
+ if (lastupdated == NULL)
+ return (1);
+ if (!timespecisset(lastupdated))
+ return (1);
- getnanotime(&curtime);
- timespecsub(&curtime, lastupdated);
- return ((curtime.tv_sec < 0 || curtime.tv_sec > acpi_battery_get_info_expire()));
+ getnanotime(&curtime);
+ timespecsub(&curtime, lastupdated);
+ return (curtime.tv_sec < 0 ||
+ curtime.tv_sec > acpi_battery_get_info_expire());
}
static __inline void
acpi_cmbat_info_updated(struct timespec *lastupdated)
{
-
- if (lastupdated != NULL) {
- getnanotime(lastupdated);
- }
+ if (lastupdated != NULL)
+ getnanotime(lastupdated);
}
static void
acpi_cmbat_get_bst(void *context)
{
- device_t dev;
- struct acpi_cmbat_softc *sc;
- ACPI_STATUS as;
- ACPI_OBJECT *res, *tmp;
- ACPI_HANDLE h;
- ACPI_BUFFER bst_buffer;
-
- dev = context;
- sc = device_get_softc(dev);
- h = acpi_get_handle(dev);
- bst_buffer.Pointer = NULL;
-
- if (!acpi_cmbat_info_expired(&sc->bst_lastupdated)) {
- return;
- }
-
- if (sc->bst_updating) {
- return;
- }
- sc->bst_updating = 1;
-
- bst_buffer.Length = ACPI_ALLOCATE_BUFFER;
- if (ACPI_FAILURE(as = AcpiEvaluateObject(h, "_BST", NULL, &bst_buffer))) {
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ device_t dev;
+ struct acpi_cmbat_softc *sc;
+ ACPI_STATUS as;
+ ACPI_OBJECT *res, *tmp;
+ ACPI_HANDLE h;
+ ACPI_BUFFER bst_buffer;
+
+ dev = context;
+ sc = device_get_softc(dev);
+ h = acpi_get_handle(dev);
+ bst_buffer.Pointer = NULL;
+
+ if (!acpi_cmbat_info_expired(&sc->bst_lastupdated))
+ return;
+ if (sc->bst_updating)
+ return;
+ sc->bst_updating = 1;
+
+ bst_buffer.Length = ACPI_ALLOCATE_BUFFER;
+ as = AcpiEvaluateObject(h, "_BST", NULL, &bst_buffer);
+ if (ACPI_FAILURE(as)) {
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"error fetching current battery status -- %s\n",
AcpiFormatException(as));
- goto end;
- }
+ goto end;
+ }
- res = (ACPI_OBJECT *)bst_buffer.Pointer;
+ res = (ACPI_OBJECT *)bst_buffer.Pointer;
+ if (res == NULL || res->Type != ACPI_TYPE_PACKAGE ||
+ res->Package.Count != 4) {
- if ((res == NULL) || (res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 4)) {
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"battery status corrupted\n");
- goto end;
- }
+ goto end;
+ }
+
+ PKG_GETINT(res, tmp, 0, sc->bst.state, end);
+ PKG_GETINT(res, tmp, 1, sc->bst.rate, end);
+ PKG_GETINT(res, tmp, 2, sc->bst.cap, end);
+ PKG_GETINT(res, tmp, 3, sc->bst.volt, end);
+ acpi_cmbat_info_updated(&sc->bst_lastupdated);
- PKG_GETINT(res, tmp, 0, sc->bst.state, end);
- PKG_GETINT(res, tmp, 1, sc->bst.rate, end);
- PKG_GETINT(res, tmp, 2, sc->bst.cap, end);
- PKG_GETINT(res, tmp, 3, sc->bst.volt, end);
- acpi_cmbat_info_updated(&sc->bst_lastupdated);
end:
- if (bst_buffer.Pointer != NULL)
- AcpiOsFree(bst_buffer.Pointer);
- sc->bst_updating = 0;
+ if (bst_buffer.Pointer != NULL)
+ AcpiOsFree(bst_buffer.Pointer);
+ sc->bst_updating = 0;
}
static void
acpi_cmbat_get_bif(void *context)
{
- device_t dev;
- struct acpi_cmbat_softc *sc;
- ACPI_STATUS as;
- ACPI_OBJECT *res, *tmp;
- ACPI_HANDLE h;
- ACPI_BUFFER bif_buffer;
-
- dev = context;
- sc = device_get_softc(dev);
- h = acpi_get_handle(dev);
- bif_buffer.Pointer = NULL;
-
- if (!acpi_cmbat_info_expired(&sc->bif_lastupdated)) {
- return;
- }
-
- if (sc->bif_updating) {
- return;
- }
- sc->bif_updating = 1;
-
- bif_buffer.Length = ACPI_ALLOCATE_BUFFER;
- if (ACPI_FAILURE(as = AcpiEvaluateObject(h, "_BIF", NULL, &bif_buffer))) {
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ device_t dev;
+ struct acpi_cmbat_softc *sc;
+ ACPI_STATUS as;
+ ACPI_OBJECT *res, *tmp;
+ ACPI_HANDLE h;
+ ACPI_BUFFER bif_buffer;
+
+ dev = context;
+ sc = device_get_softc(dev);
+ h = acpi_get_handle(dev);
+ bif_buffer.Pointer = NULL;
+
+ if (!acpi_cmbat_info_expired(&sc->bif_lastupdated))
+ return;
+ if (sc->bif_updating)
+ return;
+ sc->bif_updating = 1;
+
+ bif_buffer.Length = ACPI_ALLOCATE_BUFFER;
+ as = AcpiEvaluateObject(h, "_BIF", NULL, &bif_buffer);
+ if (ACPI_FAILURE(as)) {
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"error fetching current battery info -- %s\n",
AcpiFormatException(as));
- goto end;
- }
+ goto end;
+ }
- res = (ACPI_OBJECT *)bif_buffer.Pointer;
+ res = (ACPI_OBJECT *)bif_buffer.Pointer;
+ if (res == NULL || res->Type != ACPI_TYPE_PACKAGE ||
+ res->Package.Count != 13) {
- if ((res == NULL) || (res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 13)) {
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"battery info corrupted\n");
- goto end;
- }
+ goto end;
+ }
+
+ PKG_GETINT(res, tmp, 0, sc->bif.unit, end);
+ PKG_GETINT(res, tmp, 1, sc->bif.dcap, end);
+ PKG_GETINT(res, tmp, 2, sc->bif.lfcap, end);
+ PKG_GETINT(res, tmp, 3, sc->bif.btech, end);
+ PKG_GETINT(res, tmp, 4, sc->bif.dvol, end);
+ PKG_GETINT(res, tmp, 5, sc->bif.wcap, end);
+ PKG_GETINT(res, tmp, 6, sc->bif.lcap, end);
+ PKG_GETINT(res, tmp, 7, sc->bif.gra1, end);
+ PKG_GETINT(res, tmp, 8, sc->bif.gra2, end);
+ PKG_GETSTR(res, tmp, 9, sc->bif.model, ACPI_CMBAT_MAXSTRLEN, end);
+ PKG_GETSTR(res, tmp, 10, sc->bif.serial, ACPI_CMBAT_MAXSTRLEN, end);
+ PKG_GETSTR(res, tmp, 11, sc->bif.type, ACPI_CMBAT_MAXSTRLEN, end);
+ PKG_GETSTR(res, tmp, 12, sc->bif.oeminfo, ACPI_CMBAT_MAXSTRLEN, end);
+ acpi_cmbat_info_updated(&sc->bif_lastupdated);
- PKG_GETINT(res, tmp, 0, sc->bif.unit, end);
- PKG_GETINT(res, tmp, 1, sc->bif.dcap, end);
- PKG_GETINT(res, tmp, 2, sc->bif.lfcap, end);
- PKG_GETINT(res, tmp, 3, sc->bif.btech, end);
- PKG_GETINT(res, tmp, 4, sc->bif.dvol, end);
- PKG_GETINT(res, tmp, 5, sc->bif.wcap, end);
- PKG_GETINT(res, tmp, 6, sc->bif.lcap, end);
- PKG_GETINT(res, tmp, 7, sc->bif.gra1, end);
- PKG_GETINT(res, tmp, 8, sc->bif.gra2, end);
- PKG_GETSTR(res, tmp, 9, sc->bif.model, ACPI_CMBAT_MAXSTRLEN, end);
- PKG_GETSTR(res, tmp, 10, sc->bif.serial, ACPI_CMBAT_MAXSTRLEN, end);
- PKG_GETSTR(res, tmp, 11, sc->bif.type, ACPI_CMBAT_MAXSTRLEN, end);
- PKG_GETSTR(res, tmp, 12, sc->bif.oeminfo, ACPI_CMBAT_MAXSTRLEN, end);
- acpi_cmbat_info_updated(&sc->bif_lastupdated);
end:
- if (bif_buffer.Pointer != NULL)
- AcpiOsFree(bif_buffer.Pointer);
- sc->bif_updating = 0;
+ if (bif_buffer.Pointer != NULL)
+ AcpiOsFree(bif_buffer.Pointer);
+ sc->bif_updating = 0;
}
static void
acpi_cmbat_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
- device_t dev;
- struct acpi_cmbat_softc *sc;
+ device_t dev;
+ struct acpi_cmbat_softc *sc;
- dev = (device_t)context;
- if ((sc = device_get_softc(dev)) == NULL) {
- return;
- }
+ dev = (device_t)context;
+ if ((sc = device_get_softc(dev)) == NULL)
+ return;
- switch (notify) {
- case ACPI_BATTERY_BST_CHANGE:
- timespecclear(&sc->bst_lastupdated);
- break;
- case ACPI_BATTERY_BIF_CHANGE:
- timespecclear(&sc->bif_lastupdated);
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_get_bif, dev);
- break;
- default:
- break;
- }
+ switch (notify) {
+ case ACPI_BATTERY_BST_CHANGE:
+ timespecclear(&sc->bst_lastupdated);
+ break;
+ case ACPI_BATTERY_BIF_CHANGE:
+ timespecclear(&sc->bif_lastupdated);
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_get_bif, dev);
+ break;
+ default:
+ break;
+ }
}
static int
acpi_cmbat_probe(device_t dev)
{
+ if (acpi_get_type(dev) == ACPI_TYPE_DEVICE &&
+ !acpi_disabled("cmbat") && acpi_MatchHid(dev, "PNP0C0A")) {
- if ((acpi_get_type(dev) == ACPI_TYPE_DEVICE) &&
- !acpi_disabled("cmbat") &&
- acpi_MatchHid(dev, "PNP0C0A")) {
- /*
- * Set device description.
- */
- device_set_desc(dev, "Control method Battery");
- return (0);
- }
- return (ENXIO);
+ device_set_desc(dev, "Control method Battery");
+ return (0);
+ }
+ return (ENXIO);
}
static int
acpi_cmbat_attach(device_t dev)
{
- int error;
- ACPI_HANDLE handle;
- struct acpi_cmbat_softc *sc;
-
- if ((sc = device_get_softc(dev)) == NULL) {
- return (ENXIO);
- }
-
- handle = acpi_get_handle(dev);
+ int error;
+ ACPI_HANDLE handle;
+ struct acpi_cmbat_softc *sc;
- AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
- acpi_cmbat_notify_handler, dev);
+ if ((sc = device_get_softc(dev)) == NULL)
+ return (ENXIO);
- sc->bif_updating = sc->bst_updating = 0;
- sc->dev = dev;
+ handle = acpi_get_handle(dev);
+ AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
+ acpi_cmbat_notify_handler, dev);
- timespecclear(&sc->bif_lastupdated);
- timespecclear(&sc->bst_lastupdated);
+ sc->bif_updating = sc->bst_updating = 0;
+ sc->dev = dev;
- if (acpi_cmbat_units == 0) {
- if ((error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BIF,
- acpi_cmbat_ioctl, NULL)) != 0) {
- return (error);
- }
- if ((error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BST,
- acpi_cmbat_ioctl, NULL)) != 0) {
- return (error);
- }
- }
+ timespecclear(&sc->bif_lastupdated);
+ timespecclear(&sc->bst_lastupdated);
- if ((error = acpi_battery_register(ACPI_BATT_TYPE_CMBAT,
- acpi_cmbat_units)) != 0) {
+ if (acpi_cmbat_units == 0) {
+ error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BIF,
+ acpi_cmbat_ioctl, NULL);
+ if (error != 0)
+ return (error);
+ error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BST,
+ acpi_cmbat_ioctl, NULL);
+ if (error != 0)
return (error);
- }
+ }
- acpi_cmbat_units++;
- timespecclear(&acpi_cmbat_info_lastupdated);
- sc->initializing = 0;
+ error = acpi_battery_register(ACPI_BATT_TYPE_CMBAT, acpi_cmbat_units);
+ if (error != 0)
+ return (error);
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev);
- return (0);
+ acpi_cmbat_units++;
+ timespecclear(&acpi_cmbat_info_lastupdated);
+ sc->initializing = 0;
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev);
+
+ return (0);
}
static int
acpi_cmbat_resume(device_t dev)
{
-
- AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev);
- return (0);
+ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev);
+ return (0);
}
static device_method_t acpi_cmbat_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, acpi_cmbat_probe),
- DEVMETHOD(device_attach, acpi_cmbat_attach),
- DEVMETHOD(device_resume, acpi_cmbat_resume),
+ /* Device interface */
+ DEVMETHOD(device_probe, acpi_cmbat_probe),
+ DEVMETHOD(device_attach, acpi_cmbat_attach),
+ DEVMETHOD(device_resume, acpi_cmbat_resume),
- {0, 0}
+ {0, 0}
};
static driver_t acpi_cmbat_driver = {
- "acpi_cmbat",
- acpi_cmbat_methods,
- sizeof(struct acpi_cmbat_softc),
+ "acpi_cmbat",
+ acpi_cmbat_methods,
+ sizeof(struct acpi_cmbat_softc),
};
static devclass_t acpi_cmbat_devclass;
@@ -389,327 +373,304 @@ DRIVER_MODULE(acpi_cmbat, acpi, acpi_cmbat_driver, acpi_cmbat_devclass, 0, 0);
static int
acpi_cmbat_ioctl(u_long cmd, caddr_t addr, void *arg)
{
- device_t dev;
- union acpi_battery_ioctl_arg *ioctl_arg;
- struct acpi_cmbat_softc *sc;
- struct acpi_bif *bifp;
- struct acpi_bst *bstp;
-
- ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
- if ((dev = devclass_get_device(acpi_cmbat_devclass,
- ioctl_arg->unit)) == NULL) {
- return (ENXIO);
- }
-
- if ((sc = device_get_softc(dev)) == NULL) {
- return (ENXIO);
- }
+ device_t dev;
+ union acpi_battery_ioctl_arg *ioctl_arg;
+ struct acpi_cmbat_softc *sc;
+ struct acpi_bif *bifp;
+ struct acpi_bst *bstp;
+
+ ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
+ dev = devclass_get_device(acpi_cmbat_devclass, ioctl_arg->unit);
+ if (dev == NULL)
+ return (ENXIO);
+ sc = device_get_softc(dev);
+ if (sc == NULL)
+ return (ENXIO);
- /*
- * No security check required: information retrieval only. If
- * new functions are added here, a check might be required.
- */
-
- switch (cmd) {
- case ACPIIO_CMBAT_GET_BIF:
- acpi_cmbat_get_bif(dev);
- bifp = &ioctl_arg->bif;
- bifp->unit = sc->bif.unit;
- bifp->dcap = sc->bif.dcap;
- bifp->lfcap = sc->bif.lfcap;
- bifp->btech = sc->bif.btech;
- bifp->dvol = sc->bif.dvol;
- bifp->wcap = sc->bif.wcap;
- bifp->lcap = sc->bif.lcap;
- bifp->gra1 = sc->bif.gra1;
- bifp->gra2 = sc->bif.gra2;
- strncpy(bifp->model, sc->bif.model, sizeof(sc->bif.model));
- strncpy(bifp->serial, sc->bif.serial, sizeof(sc->bif.serial));
- strncpy(bifp->type, sc->bif.type, sizeof(sc->bif.type));
- strncpy(bifp->oeminfo, sc->bif.oeminfo, sizeof(sc->bif.oeminfo));
- break;
-
- case ACPIIO_CMBAT_GET_BST:
- bstp = &ioctl_arg->bst;
- if (acpi_BatteryIsPresent(dev)) {
- acpi_cmbat_get_bst(dev);
- bstp->state = sc->bst.state;
- bstp->rate = sc->bst.rate;
- bstp->cap = sc->bst.cap;
- bstp->volt = sc->bst.volt;
- } else
- bstp->state = ACPI_BATT_STAT_NOT_PRESENT;
- break;
+ /*
+ * No security check required: information retrieval only. If
+ * new functions are added here, a check might be required.
+ */
+ switch (cmd) {
+ case ACPIIO_CMBAT_GET_BIF:
+ acpi_cmbat_get_bif(dev);
+ bifp = &ioctl_arg->bif;
+ bifp->unit = sc->bif.unit;
+ bifp->dcap = sc->bif.dcap;
+ bifp->lfcap = sc->bif.lfcap;
+ bifp->btech = sc->bif.btech;
+ bifp->dvol = sc->bif.dvol;
+ bifp->wcap = sc->bif.wcap;
+ bifp->lcap = sc->bif.lcap;
+ bifp->gra1 = sc->bif.gra1;
+ bifp->gra2 = sc->bif.gra2;
+ strncpy(bifp->model, sc->bif.model, sizeof(sc->bif.model));
+ strncpy(bifp->serial, sc->bif.serial, sizeof(sc->bif.serial));
+ strncpy(bifp->type, sc->bif.type, sizeof(sc->bif.type));
+ strncpy(bifp->oeminfo, sc->bif.oeminfo, sizeof(sc->bif.oeminfo));
+ break;
+ case ACPIIO_CMBAT_GET_BST:
+ bstp = &ioctl_arg->bst;
+ if (acpi_BatteryIsPresent(dev)) {
+ acpi_cmbat_get_bst(dev);
+ bstp->state = sc->bst.state;
+ bstp->rate = sc->bst.rate;
+ bstp->cap = sc->bst.cap;
+ bstp->volt = sc->bst.volt;
+ } else {
+ bstp->state = ACPI_BATT_STAT_NOT_PRESENT;
}
+ break;
+ default:
+ break;
+ }
- return (0);
+ return (0);
}
static __inline int
acpi_cmbat_is_bst_valid(struct acpi_bst *bst)
{
- if (bst->state >= ACPI_BATT_STAT_MAX ||
- bst->cap == 0xffffffff ||
- bst->volt == 0xffffffff) {
- return (0);
- }
+ if (bst->state >= ACPI_BATT_STAT_MAX || bst->cap == 0xffffffff ||
+ bst->volt == 0xffffffff)
+ return (0);
+ else
return (1);
}
static __inline int
acpi_cmbat_is_bif_valid(struct acpi_bif *bif)
{
- if (bif->lfcap == 0) {
- return (0);
- }
-
+ if (bif->lfcap == 0)
+ return (0);
+ else
return (1);
}
static int
acpi_cmbat_get_total_battinfo(struct acpi_battinfo *battinfo)
{
- int i;
- int error;
- int batt_stat;
- int valid_rate, valid_units;
- int cap, min;
- int total_cap, total_min, total_full;
- device_t dev;
- struct acpi_cmbat_softc *sc;
- static int bat_units = 0;
- static struct acpi_cmbat_softc **bat = NULL;
-
- cap = min = -1;
- batt_stat = ACPI_BATT_STAT_NOT_PRESENT;
- error = 0;
-
- /* Allocate array of softc pointers */
- if (bat_units != acpi_cmbat_units) {
- if (bat != NULL) {
- free(bat, M_ACPICMBAT);
- bat = NULL;
- }
- bat_units = 0;
- }
+ int i;
+ int error;
+ int batt_stat;
+ int valid_rate, valid_units;
+ int cap, min;
+ int total_cap, total_min, total_full;
+ device_t dev;
+ struct acpi_cmbat_softc *sc;
+ static int bat_units = 0;
+ static struct acpi_cmbat_softc **bat = NULL;
+
+ cap = min = -1;
+ batt_stat = ACPI_BATT_STAT_NOT_PRESENT;
+ error = 0;
+
+ /* Allocate array of softc pointers */
+ if (bat_units != acpi_cmbat_units) {
+ if (bat != NULL) {
+ free(bat, M_ACPICMBAT);
+ bat = NULL;
+ }
+ bat_units = 0;
+ }
+ if (bat == NULL) {
+ bat_units = acpi_cmbat_units;
+ bat = malloc(sizeof(struct acpi_cmbat_softc *) * bat_units,
+ M_ACPICMBAT, M_NOWAIT);
if (bat == NULL) {
- bat_units = acpi_cmbat_units;
- bat = malloc(sizeof(struct acpi_cmbat_softc *) * bat_units,
- M_ACPICMBAT, M_NOWAIT);
- if (bat == NULL) {
- error = ENOMEM;
- goto out;
- }
-
- /* Collect softc pointers */
- for (i = 0; i < acpi_cmbat_units; i++) {
- if ((dev = devclass_get_device(acpi_cmbat_devclass, i)) == NULL) {
- error = ENXIO;
- goto out;
- }
-
- if ((sc = device_get_softc(dev)) == NULL) {
- error = ENXIO;
- goto out;
- }
-
- bat[i] = sc;
- }
+ error = ENOMEM;
+ goto out;
}
- /* Get battery status, valid rate and valid units */
- batt_stat = valid_rate = valid_units = 0;
+ /* Collect softc pointers */
for (i = 0; i < acpi_cmbat_units; i++) {
- bat[i]->present = acpi_BatteryIsPresent(bat[i]->dev);
- if (!bat[i]->present)
- continue;
-
- acpi_cmbat_get_bst(bat[i]->dev);
-
- /* If battey not installed, we get strange values */
- if (!acpi_cmbat_is_bst_valid(&(bat[i]->bst)) ||
- !acpi_cmbat_is_bif_valid(&(bat[i]->bif))) {
- bat[i]->present = 0;
- continue;
- }
-
- valid_units++;
-
- bat[i]->cap = 100 * bat[i]->bst.cap / bat[i]->bif.lfcap;
-
- batt_stat |= bat[i]->bst.state;
-
- if (bat[i]->bst.rate > 0) {
- /*
- * XXX Hack to calculate total battery time.
- * Systems with 2 or more battries, they may get used
- * one by one, thus bst.rate is set only to the one
- * in use. For remaining batteries bst.rate = 0, which
- * makes it impossible to calculate remaining time.
- * Some other systems may need sum of bst.rate in
- * dis-charging state.
- * There for we sum up the bst.rate that is valid
- * (in dis-charging state), and use the sum to
- * calcutate remaining batteries' time.
- */
- if (bat[i]->bst.state & ACPI_BATT_STAT_DISCHARG) {
- valid_rate += bat[i]->bst.rate;
- }
- }
- }
-
- /* Calculate total battery capacity and time */
- total_cap = total_min = total_full = 0;
- for (i = 0; i < acpi_cmbat_units; i++) {
- if (!bat[i]->present) {
- continue;
- }
-
- if (valid_rate > 0) {
- /* Use the sum of bst.rate */
- bat[i]->min = 60 * bat[i]->bst.cap / valid_rate;
- } else if (bat[i]->full_charge_time > 0) {
- bat[i]->min = (bat[i]->full_charge_time * bat[i]->cap) / 100;
- } else {
- /* Couldn't find valid rate and full battery time */
- bat[i]->min = 0;
- }
- total_min += bat[i]->min;
- total_cap += bat[i]->cap;
- total_full += bat[i]->full_charge_time;
- }
-
- /* Battery life */
- if (valid_units == 0) {
- cap = -1;
- batt_stat = ACPI_BATT_STAT_NOT_PRESENT;
+ if ((dev = devclass_get_device(acpi_cmbat_devclass, i)) == NULL) {
+ error = ENXIO;
+ goto out;
+ }
+ if ((sc = device_get_softc(dev)) == NULL) {
+ error = ENXIO;
+ goto out;
+ }
+ bat[i] = sc;
+ }
+ }
+
+ /* Get battery status, valid rate and valid units */
+ batt_stat = valid_rate = valid_units = 0;
+ for (i = 0; i < acpi_cmbat_units; i++) {
+ bat[i]->present = acpi_BatteryIsPresent(bat[i]->dev);
+ if (!bat[i]->present)
+ continue;
+
+ acpi_cmbat_get_bst(bat[i]->dev);
+
+ /* If battery not installed, we get strange values */
+ if (!acpi_cmbat_is_bst_valid(&(bat[i]->bst)) ||
+ !acpi_cmbat_is_bif_valid(&(bat[i]->bif))) {
+
+ bat[i]->present = 0;
+ continue;
+ }
+
+ valid_units++;
+ bat[i]->cap = 100 * bat[i]->bst.cap / bat[i]->bif.lfcap;
+ batt_stat |= bat[i]->bst.state;
+
+ if (bat[i]->bst.rate > 0) {
+ /*
+ * XXX Hack to calculate total battery time.
+ * Systems with 2 or more battries, they may get used
+ * one by one, thus bst.rate is set only to the one
+ * in use. For remaining batteries bst.rate = 0, which
+ * makes it impossible to calculate remaining time.
+ * Some other systems may need sum of bst.rate in
+ * dis-charging state.
+ * There for we sum up the bst.rate that is valid
+ * (in dis-charging state), and use the sum to
+ * calcutate remaining batteries' time.
+ */
+ if (bat[i]->bst.state & ACPI_BATT_STAT_DISCHARG)
+ valid_rate += bat[i]->bst.rate;
+ }
+ }
+
+ /* Calculate total battery capacity and time */
+ total_cap = total_min = total_full = 0;
+ for (i = 0; i < acpi_cmbat_units; i++) {
+ if (!bat[i]->present)
+ continue;
+
+ if (valid_rate > 0) {
+ /* Use the sum of bst.rate */
+ bat[i]->min = 60 * bat[i]->bst.cap / valid_rate;
+ } else if (bat[i]->full_charge_time > 0) {
+ bat[i]->min = (bat[i]->full_charge_time * bat[i]->cap) / 100;
} else {
- cap = total_cap / valid_units;
+ /* Couldn't find valid rate and full battery time */
+ bat[i]->min = 0;
}
+ total_min += bat[i]->min;
+ total_cap += bat[i]->cap;
+ total_full += bat[i]->full_charge_time;
+ }
- /* Battery time */
- if (valid_units == 0) {
- min = -1;
- } else if (valid_rate == 0 || (batt_stat & ACPI_BATT_STAT_CHARGING)) {
- if (total_full == 0) {
- min = -1;
- } else {
- min = (total_full * cap) / 100;
- }
- } else {
- min = total_min;
- }
+ /* Battery life */
+ if (valid_units == 0) {
+ cap = -1;
+ batt_stat = ACPI_BATT_STAT_NOT_PRESENT;
+ } else {
+ cap = total_cap / valid_units;
+ }
+
+ /* Battery time */
+ if (valid_units == 0) {
+ min = -1;
+ } else if (valid_rate == 0 || (batt_stat & ACPI_BATT_STAT_CHARGING)) {
+ if (total_full == 0)
+ min = -1;
+ else
+ min = (total_full * cap) / 100;
+ } else {
+ min = total_min;
+ }
+ acpi_cmbat_info_updated(&acpi_cmbat_info_lastupdated);
- acpi_cmbat_info_updated(&acpi_cmbat_info_lastupdated);
out:
- battinfo->cap = cap;
- battinfo->min = min;
- battinfo->state = batt_stat;
+ battinfo->cap = cap;
+ battinfo->min = min;
+ battinfo->state = batt_stat;
- return (error);
+ return (error);
}
static void
acpi_cmbat_init_battery(void *arg)
{
- int retry;
- device_t dev = (device_t)arg;
- struct acpi_cmbat_softc *sc = device_get_softc(dev);
-#define ACPI_CMBAT_RETRY_MAX 6
-
- if (sc->initializing) {
- return;
- }
-
- sc->initializing = 1;
-
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "battery initialization start\n");
-
- for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
- sc->present = acpi_BatteryIsPresent(dev);
- if (!sc->present) {
- continue;
- }
+ int retry;
+ device_t dev = (device_t)arg;
+ struct acpi_cmbat_softc *sc = device_get_softc(dev);
- timespecclear(&sc->bst_lastupdated);
- timespecclear(&sc->bif_lastupdated);
+ if (sc->initializing)
+ return;
- acpi_cmbat_get_bst(dev);
+ sc->initializing = 1;
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "battery initialization start\n");
- if (!acpi_cmbat_is_bst_valid(&sc->bst)) {
- continue;
- }
+ for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
+ sc->present = acpi_BatteryIsPresent(dev);
+ if (!sc->present)
+ continue;
- acpi_cmbat_get_bif(dev);
+ timespecclear(&sc->bst_lastupdated);
+ timespecclear(&sc->bif_lastupdated);
- if (!acpi_cmbat_is_bif_valid(&sc->bif)) {
- continue;
- }
+ acpi_cmbat_get_bst(dev);
+ if (!acpi_cmbat_is_bst_valid(&sc->bst))
+ continue;
- break;
- }
+ acpi_cmbat_get_bif(dev);
+ if (!acpi_cmbat_is_bif_valid(&sc->bif))
+ continue;
+ break;
+ }
- if (retry == ACPI_CMBAT_RETRY_MAX)
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "battery initialization failed, giving up\n");
- else
- ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
- "battery initialization done, tried %d times\n",
- retry+1);
-
- sc->initializing = 0;
+ if (retry == ACPI_CMBAT_RETRY_MAX) {
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "battery initialization failed, giving up\n");
+ } else {
+ ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
+ "battery initialization done, tried %d times\n", retry + 1);
+ }
+ sc->initializing = 0;
}
/*
* Public interfaces.
*/
-
int
acpi_cmbat_get_battinfo(int unit, struct acpi_battinfo *battinfo)
{
- int error;
- device_t dev;
- struct acpi_cmbat_softc *sc;
-
- if (unit == -1) {
- return (acpi_cmbat_get_total_battinfo(battinfo));
- }
-
- if (acpi_cmbat_info_expired(&acpi_cmbat_info_lastupdated)) {
- error = acpi_cmbat_get_total_battinfo(battinfo);
- if (error) {
- goto out;
- }
- }
-
- error = 0;
- if (unit >= acpi_cmbat_units) {
- error = ENXIO;
- goto out;
- }
-
- if ((dev = devclass_get_device(acpi_cmbat_devclass, unit)) == NULL) {
- error = ENXIO;
- goto out;
- }
-
- if ((sc = device_get_softc(dev)) == NULL) {
- error = ENXIO;
- goto out;
- }
+ int error;
+ device_t dev;
+ struct acpi_cmbat_softc *sc;
+
+ if (unit == -1)
+ return (acpi_cmbat_get_total_battinfo(battinfo));
+
+ if (acpi_cmbat_info_expired(&acpi_cmbat_info_lastupdated)) {
+ error = acpi_cmbat_get_total_battinfo(battinfo);
+ if (error)
+ goto out;
+ }
+
+ error = 0;
+ if (unit >= acpi_cmbat_units) {
+ error = ENXIO;
+ goto out;
+ }
+
+ if ((dev = devclass_get_device(acpi_cmbat_devclass, unit)) == NULL) {
+ error = ENXIO;
+ goto out;
+ }
+ if ((sc = device_get_softc(dev)) == NULL) {
+ error = ENXIO;
+ goto out;
+ }
+
+ if (!sc->present) {
+ battinfo->cap = -1;
+ battinfo->min = -1;
+ battinfo->state = ACPI_BATT_STAT_NOT_PRESENT;
+ } else {
+ battinfo->cap = sc->cap;
+ battinfo->min = sc->min;
+ battinfo->state = sc->bst.state;
+ }
- if (!sc->present) {
- battinfo->cap = -1;
- battinfo->min = -1;
- battinfo->state = ACPI_BATT_STAT_NOT_PRESENT;
- } else {
- battinfo->cap = sc->cap;
- battinfo->min = sc->min;
- battinfo->state = sc->bst.state;
- }
out:
- return (error);
+ return (error);
}
-
OpenPOWER on IntegriCloud