Expose bif_capacity as the 'design capacity' through an acpibat sensor,
authorlandry <landry@openbsd.org>
Fri, 23 May 2014 19:17:39 +0000 (19:17 +0000)
committerlandry <landry@openbsd.org>
Fri, 23 May 2014 19:17:39 +0000 (19:17 +0000)
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@

sys/dev/acpi/acpibat.c
sys/dev/acpi/acpidev.h

index ddde2de..093be74 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpibat.c,v 1.59 2011/10/16 11:59:21 kettenis Exp $ */
+/* $OpenBSD: acpibat.c,v 1.60 2014/05/23 19:17:39 landry Exp $ */
 /*
  * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
  *
@@ -163,6 +163,12 @@ acpibat_monitor(struct acpibat_softc *sc)
        sensor_attach(&sc->sc_sensdev, &sc->sc_sens[7]);
        sc->sc_sens[7].value = sc->sc_bst.bst_voltage * 1000;
 
+       strlcpy(sc->sc_sens[8].desc, "design capacity",
+           sizeof(sc->sc_sens[8].desc));
+       sc->sc_sens[8].type = type;
+       sensor_attach(&sc->sc_sensdev, &sc->sc_sens[8]);
+       sc->sc_sens[8].value = sc->sc_bif.bif_capacity * 1000;
+
        sensordev_install(&sc->sc_sensdev);
 }
 
@@ -176,7 +182,7 @@ acpibat_refresh(void *arg)
            sc->sc_devnode->name);
 
        if (!sc->sc_bat_present) {
-               for (i = 0; i < 8; i++) {
+               for (i = 0; i < 9; i++) {
                        sc->sc_sens[i].value = 0;
                        sc->sc_sens[i].status = SENSOR_S_UNSPEC;
                        sc->sc_sens[i].flags = SENSOR_FINVALID;
@@ -274,6 +280,16 @@ acpibat_refresh(void *arg)
                sc->sc_sens[7].status = SENSOR_S_UNSPEC;
                sc->sc_sens[7].flags = 0;
        }
+
+       if (sc->sc_bif.bif_capacity == BIF_UNKNOWN) {
+               sc->sc_sens[8].value = 0;
+               sc->sc_sens[8].status = SENSOR_S_UNKNOWN;
+               sc->sc_sens[8].flags = SENSOR_FUNKNOWN;
+       } else {
+               sc->sc_sens[8].value = sc->sc_bif.bif_capacity * 1000;
+               sc->sc_sens[8].status = SENSOR_S_UNSPEC;
+               sc->sc_sens[8].flags = 0;
+       }
        acpi_record_event(sc->sc_acpi, APM_POWER_CHANGE);
 }
 
index 4db5e1d..4109d13 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpidev.h,v 1.33 2012/07/13 10:37:40 pirofti Exp $ */
+/* $OpenBSD: acpidev.h,v 1.34 2014/05/23 19:17:39 landry Exp $ */
 /*
  * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
  * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
@@ -278,7 +278,7 @@ struct acpibat_softc {
        struct acpibat_bst      sc_bst;
        volatile int            sc_bat_present;
 
-       struct ksensor          sc_sens[8];
+       struct ksensor          sc_sens[9];
        struct ksensordev       sc_sensdev;
 };