From: Alexey Starikovskiy <aystarik@gmail.com>
To: Ferenc Wagner <wferi@niif.hu>
Cc: linux-acpi@vger.kernel.org
Subject: Re: battery: current a factor of 10 off?
Date: Fri, 21 Nov 2008 22:41:01 +0800 [thread overview]
Message-ID: <4926C87D.20308@gmail.com> (raw)
In-Reply-To: <8f8ff01d0811202009r2d1fedcct9a383f9362c5a064@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1507 bytes --]
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@niif.hu> 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@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>>
[-- Attachment #2: convert_discharge_energy_to_current.patch --]
[-- Type: text/x-diff, Size: 1255 bytes --]
ACPI:battery: Convert discharge energy rate to current properly
From: Alexey Starikovskiy <astarikovskiy@suse.de>
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@suse.de>
---
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:
next prev parent reply other threads:[~2008-11-21 14:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-21 0:33 battery: current a factor of 10 off? Ferenc Wagner
2008-11-21 1:31 ` Henrique de Moraes Holschuh
2008-11-21 4:09 ` Alexey Starikovskiy
2008-11-21 14:41 ` Alexey Starikovskiy [this message]
2008-11-24 1:43 ` battery: current a factor of 10 off? [fix confirmed] Ferenc Wagner
2008-11-24 7:44 ` Alexey Starikovskiy
2008-11-24 9:31 ` Ferenc Wagner
2008-11-26 22:27 ` battery: current a factor of 10 off? Len Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4926C87D.20308@gmail.com \
--to=aystarik@gmail.com \
--cc=linux-acpi@vger.kernel.org \
--cc=wferi@niif.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox