acpibat(4) diff to report charge/discharge rate neatly

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

acpibat(4) diff to report charge/discharge rate neatly

Vladimir Kirillov-2
Hello, tech@!

Due to ACPI spec, _BST method returns the rate value
in milliwats or milliamperes according to the unit reported by _BIF.

Tweak acpibat so sysctl sees the data like this:
hw.sensors.acpibat0.power0=14.95 W (rate)

Index: acpibat.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpibat.c,v
retrieving revision 1.58
diff -u -p -r1.58 acpibat.c
--- acpibat.c 10 Nov 2010 21:40:55 -0000 1.58
+++ acpibat.c 19 Nov 2010 22:55:46 -0000
@@ -146,7 +146,8 @@ acpibat_monitor(struct acpibat_softc *sc
  sc->sc_sens[4].value = sc->sc_bst.bst_state;
 
  strlcpy(sc->sc_sens[5].desc, "rate", sizeof(sc->sc_sens[5].desc));
- sc->sc_sens[5].type = SENSOR_INTEGER;
+ sc->sc_sens[5].type = sc->sc_bif.bif_power_unit ?
+    SENSOR_AMPS : SENSOR_WATTS;
  sensor_attach(&sc->sc_sensdev, &sc->sc_sens[5]);
  sc->sc_sens[5].value = sc->sc_bst.bst_rate;
 
@@ -242,7 +243,8 @@ acpibat_refresh(void *arg)
  sc->sc_sens[5].status = SENSOR_S_UNKNOWN;
  sc->sc_sens[5].flags = SENSOR_FUNKNOWN;
  } else {
- sc->sc_sens[5].value = sc->sc_bst.bst_rate;
+ /* reported in milli{watts,ampers} */
+ sc->sc_sens[5].value = sc->sc_bst.bst_rate * 1000;
  sc->sc_sens[5].status = SENSOR_S_UNSPEC;
  sc->sc_sens[5].flags = 0;
  }