From 50c79b3c2b003139c66343c7b805abfae1d2b424 Mon Sep 17 00:00:00 2001 From: landry Date: Fri, 23 May 2014 19:17:39 +0000 Subject: [PATCH] Expose bif_capacity as the 'design capacity' through an acpibat sensor, 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 | 20 ++++++++++++++++++-- sys/dev/acpi/acpidev.h | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sys/dev/acpi/acpibat.c b/sys/dev/acpi/acpibat.c index ddde2de8d89..093be741466 100644 --- a/sys/dev/acpi/acpibat.c +++ b/sys/dev/acpi/acpibat.c @@ -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 * @@ -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); } diff --git a/sys/dev/acpi/acpidev.h b/sys/dev/acpi/acpidev.h index 4db5e1d1c1f..4109d131d87 100644 --- a/sys/dev/acpi/acpidev.h +++ b/sys/dev/acpi/acpidev.h @@ -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 * Copyright (c) 2005 Thorsten Lockert @@ -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; }; -- 2.20.1