summaryrefslogtreecommitdiff
path: root/sys/dev/acpi
diff options
context:
space:
mode:
authorJordan Hargrave <jordan@cvs.openbsd.org>2008-06-13 05:50:22 +0000
committerJordan Hargrave <jordan@cvs.openbsd.org>2008-06-13 05:50:22 +0000
commitc33f6b0a242ce5cad7e2e07c078c101448f50652 (patch)
tree390a3cdbfac04f3da91f9f2e6ae62ce040a8df0d /sys/dev/acpi
parent91137c19cbfda000e32e569812b3a0989a890e9f (diff)
Properly handle battery insertion/removal
ok @marco
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r--sys/dev/acpi/acpibat.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/sys/dev/acpi/acpibat.c b/sys/dev/acpi/acpibat.c
index d1a837bb22d..fc8ac6bc03c 100644
--- a/sys/dev/acpi/acpibat.c
+++ b/sys/dev/acpi/acpibat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpibat.c,v 1.49 2008/06/01 17:59:55 marco Exp $ */
+/* $OpenBSD: acpibat.c,v 1.50 2008/06/13 05:50:21 jordan Exp $ */
/*
* Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
*
@@ -77,7 +77,8 @@ acpibat_attach(struct device *parent, struct device *self, void *aux)
return;
}
- if ((sc->sc_bat_present = aml_val2int(&res) & STA_BATTERY) != 0) {
+ if ((res.v_integer & STA_BATTERY) != 0) {
+ sc->sc_bat_present = 1;
acpibat_getbif(sc);
acpibat_getbst(sc);
@@ -91,8 +92,10 @@ acpibat_attach(struct device *parent, struct device *self, void *aux)
if (sc->sc_bif.bif_oem[0])
printf(" oem \"%s\"", sc->sc_bif.bif_oem);
printf("\n");
- } else
+ } else {
+ sc->sc_bat_present = 0;
printf(": %s not present\n", sc->sc_devnode->name);
+ }
aml_freevalue(&res);
@@ -289,11 +292,9 @@ acpibat_getbif(struct acpibat_softc *sc)
struct aml_value res;
int rv = EINVAL;
- if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_STA", 0, NULL, &res)) {
- dnprintf(10, "%s: no _STA\n", DEVNAME(sc));
- goto out;
- }
- aml_freevalue(&res);
+ memset(&sc->sc_bif, 0, sizeof(sc->sc_bif));
+ if (!sc->sc_bat_present)
+ return 0;
if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BIF", 0, NULL, &res)) {
dnprintf(10, "%s: no _BIF\n", DEVNAME(sc));
@@ -306,7 +307,6 @@ acpibat_getbif(struct acpibat_softc *sc)
goto out;
}
- memset(&sc->sc_bif, 0, sizeof sc->sc_bif);
sc->sc_bif.bif_power_unit = aml_val2int(res.v_package[0]);
sc->sc_bif.bif_capacity = aml_val2int(res.v_package[1]);
sc->sc_bif.bif_last_capacity = aml_val2int(res.v_package[2]);
@@ -355,6 +355,10 @@ acpibat_getbst(struct acpibat_softc *sc)
struct aml_value res;
int rv = EINVAL;
+ memset(&sc->sc_bst, 0, sizeof(sc->sc_bst));
+ if (!sc->sc_bat_present)
+ return 0;
+
if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BST", 0, NULL, &res)) {
dnprintf(10, "%s: no _BST\n", DEVNAME(sc));
goto out;
@@ -396,25 +400,31 @@ int
acpibat_notify(struct aml_node *node, int notify_type, void *arg)
{
struct acpibat_softc *sc = arg;
+ struct aml_value res;
dnprintf(10, "acpibat_notify: %.2x %s\n", notify_type,
sc->sc_devnode->name);
- switch (notify_type) {
- case 0x80: /* _BST changed */
- if (!sc->sc_bat_present) {
- printf("%s: %s: inserted\n", DEVNAME(sc),
+ /* Check if installed state of battery has changed */
+ memset(&res, 0, sizeof(res));
+ if (aml_evalname(sc->sc_acpi, node, "_STA", 0, NULL, &res) == 0) {
+ int present = (res.v_integer & STA_BATTERY);
+
+ if (!sc->sc_bat_present && present) {
+ printf("%s: %s inserted\n", DEVNAME(sc),
sc->sc_devnode->name);
sc->sc_bat_present = 1;
}
- break;
- case 0x81: /* _BIF changed */
- /* XXX consider this a device removal */
- if (sc->sc_bat_present) {
- printf("%s: %s: removed\n", DEVNAME(sc),
+ else if (sc->sc_bat_present && !present) {
+ printf("%s: %s removed\n", DEVNAME(sc),
sc->sc_devnode->name);
sc->sc_bat_present = 0;
}
+ }
+ switch (notify_type) {
+ case 0x80: /* _BST changed */
+ break;
+ case 0x81: /* _BIF changed */
break;
default:
break;