summaryrefslogtreecommitdiff
path: root/src/linux/up-device-supply.c
diff options
context:
space:
mode:
authorBenson Leung <bleung@chromium.org>2011-03-24 12:04:19 -0700
committerRichard Hughes <richard@hughsie.com>2011-03-30 14:16:21 +0100
commit95ecdb25b26c0f28c43be1f84083c75d90840fa9 (patch)
tree988322ff3532dadb553c9c95f549f7c615457fde /src/linux/up-device-supply.c
parentc98ca6f8f5d893b747779ba037b75b1d25d4821c (diff)
Support batteries that report both energy and charge.
More cleanly support batteries that report both energy and charge, but do not report power_now. One battery driver in drivers/power (bq20z75) supports reporting energy and charge natively from the fuel gauge, but does not report power_now. The previous legacy behavior would ignore the existence of charge and treat current_now as being in units of power. Signed-off-by: Benson Leung <bleung@chromium.org> Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'src/linux/up-device-supply.c')
-rw-r--r--src/linux/up-device-supply.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 95f186c..efeb856 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -554,11 +554,10 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
supply->priv->unknown_retries = 0;
}
- /* this is the new value in mWh */
+ /* this is the new value in uW */
energy_rate = fabs (sysfs_get_double (native_path, "power_now") / 1000000.0);
if (energy_rate == 0) {
- /* get the old rate, rate; which is either in uVh or uWh */
- energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
+ gdouble charge_full;
/* convert charge to energy */
if (energy == 0) {
@@ -566,8 +565,18 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
if (energy == 0)
energy = sysfs_get_double (native_path, "charge_avg") / 1000000.0;
energy *= voltage_design;
- energy_rate *= voltage_design;
}
+
+ charge_full = sysfs_get_double (native_path, "charge_full") / 1000000.0;
+ if (charge_full == 0)
+ charge_full = sysfs_get_double (native_path, "charge_full_design") / 1000000.0;
+
+ /* If charge_full exists, then current_now is always reported in uA.
+ * In the legacy case, where energy only units exist, and power_now isn't present
+ * current_now is power in uW. */
+ energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
+ if (charge_full != 0)
+ energy_rate *= voltage_design;
}
/* some batteries don't update last_full attribute */