linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hector Martin <hector@marcansoft.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexey Starikovskiy <astarikovskiy@suse.de>,
	Len Brown <lenb@kernel.org>,
	linux-acpi@vger.kernel.org
Subject: Re: [PATCH] Work around negative s16 battery current on Acer (take 3)
Date: Fri, 03 Jul 2009 01:46:28 +0200	[thread overview]
Message-ID: <4A4D46D4.7060101@marcansoft.com> (raw)
In-Reply-To: <20090702155642.0d55ee57.akpm@linux-foundation.org>

Andrew Morton wrote:
> So please always resend the full changelog (possibly after revising 
> it) with each version of a patch.
Trying again then. Hope I nailed the right Thunderbird options this time
for optimal patch submission.


Acer Aspire 8930G laptops (and possibly others) report the battery
current as a 16-bit signed negative when it is charging. It also reports
it as 0x10000 when the current is 0. This patch adds a quirk for this
which takes the absolute value of the reported current cast to an s16.
This is a DSDT bug present in the latest BIOS revision (the EC register
is 16 bits signed and the DSDT attempts to take the 16-bit two's
complement of this, which works for discharge but not charge. It also
breaks zero values because a 32-bit register is used and the high bits
aren't thrown away).

I've enabled this for all Acer systems which report in mA units. This
should be safe since it won't break compliant systems unless they report
a current above 32A, which is insane. The patch also detects the valid
32-bit value -1, which indicates unknown status, and does not attempt
the fix in that case (note that this does not conflict with 16-bit -1,
which is 65535 as read normally and gets translated to 1mA).

Signed-off-by: Hector Martin <hector@marcansoft.com>
--- linux-2.6.30/drivers/acpi/battery.c.old	2009-07-02 04:04:52.000000000 +0200
+++ linux-2.6.30/drivers/acpi/battery.c	2009-07-02 04:07:20.000000000 +0200
@@ -85,6 +85,10 @@ static const struct acpi_device_id batte
 
 MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
+/* For buggy DSDTs that report negative 16-bit values for either charging
+ * or discharging current and/or report 0 as 65536 due to bad math.
+ */
+#define QUIRK_SIGNED16_CURRENT 0x0001
 
 struct acpi_battery {
 	struct mutex lock;
@@ -112,6 +116,7 @@ struct acpi_battery {
 	int state;
 	int power_unit;
 	u8 alarm_present;
+	long quirks;
 };
 
 #define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
@@ -390,6 +395,11 @@ static int acpi_battery_get_state(struct
 				 state_offsets, ARRAY_SIZE(state_offsets));
 	battery->update_time = jiffies;
 	kfree(buffer.pointer);
+
+	if ((battery->quirks & QUIRK_SIGNED16_CURRENT) &&
+	    battery->rate_now != -1)
+		battery->rate_now = abs((s16)battery->rate_now);
+
 	return result;
 }
 
@@ -495,6 +505,14 @@ static void sysfs_remove_battery(struct 
 }
 #endif
 
+static void acpi_battery_quirks(struct acpi_battery *battery)
+{
+	battery->quirks = 0;
+	if (dmi_name_in_vendors("Acer") && battery->power_unit) {
+		battery->quirks |= QUIRK_SIGNED16_CURRENT;
+	}
+}
+
 static int acpi_battery_update(struct acpi_battery *battery)
 {
 	int result, old_present = acpi_battery_present(battery);
@@ -513,6 +531,7 @@ static int acpi_battery_update(struct ac
 		result = acpi_battery_get_info(battery);
 		if (result)
 			return result;
+		acpi_battery_quirks(battery);
 		acpi_battery_init_alarm(battery);
 	}
 #ifdef CONFIG_ACPI_SYSFS_POWER



-- 
Hector Martin (hector@marcansoft.com)
Public Key: http://www.marcansoft.com/marcan.asc


      reply	other threads:[~2009-07-02 23:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-01 18:20 [PATCH] Work around negative s16 battery current on Acer Hector Martin
2009-07-01 18:27 ` Alexey Starikovskiy
2009-07-01 18:29 ` Andrew Morton
2009-07-01 18:38   ` Alexey Starikovskiy
2009-07-01 20:19     ` Hector Martin
2009-07-02  3:51   ` Hector Martin
2009-07-02 22:56     ` Andrew Morton
2009-07-02 23:46       ` Hector Martin [this message]

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=4A4D46D4.7060101@marcansoft.com \
    --to=hector@marcansoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=astarikovskiy@suse.de \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).