Hi Ferenc,
This patch should be better -- no integer overflow.
Regards,
Alex.
Alexey Starikovskiy wrote:
Hi Ferenc,
Good catch.
ACPI battery interface report its state either in mW or in mA, and
discharge rate
in your case is reported in mW. power_supply interface does not have
such a parameter,
so current_now parameter is used for all cases. But in case of mW,
reported discharge should
be converted into mA.
Please test the attached patch.
Thanks,
Alex.
On Fri, Nov 21, 2008 at 3:33 AM, Ferenc Wagner <wferi@xxxxxxx> wrote:
Hi,
on my ThinkPad R50e the current_now reading seems something like 10
times the actual value. Documentation/power/power_supply_class.txt
says it's in uA, and a tipical discharge value is around 15259000,
that is, 15 A on my system. At the same time voltage is 11756000,
that is, 12 V, which sounds reasonable, but then the power is 15*12 VA,
ie 180 W, which is insane. However, the numerical derivative of
energy_now gives 18 W, which is both reasonable and consistent with
the assumed factor of 10 error in current_now. Is this possibly a bug
in 2.6.26.6? During a quick glance over battery.c nothing obvious
jumped at me, but I'm no expert on this.
--
Thanks,
Feri.
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
ACPI:battery: Convert discharge energy rate to current properly
From: Alexey Starikovskiy <astarikovskiy@xxxxxxx>
ACPI battery interface reports its state either in mW or in mA, and
discharge rate in your case is reported in mW. power_supply interface
does not have such a parameter, so current_now parameter is used
for all cases. But in case of mW, reported discharge should
be converted into mA.
Signed-off-by: Alexey Starikovskiy <astarikovskiy@xxxxxxx>
---
drivers/acpi/battery.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 1423b0c..0ebc04c 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -174,6 +174,15 @@ static int acpi_battery_get_property(struct power_supply *psy,
break;
case POWER_SUPPLY_PROP_CURRENT_NOW:
val->intval = battery->current_now * 1000;
+ /* if power units are mW, convert to mA by
+ dividing by current voltage (mV/1000) */
+ if (!battery->power_unit) {
+ if (battery->voltage_now) {
+ val->intval /= battery->voltage_now;
+ val->intval *= 1000;
+ } else
+ val->intval = -1;
+ }
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: