From patchwork Thu Jul 2 03:51:56 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hector Martin X-Patchwork-Id: 33603 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n623q1Oj007329 for ; Thu, 2 Jul 2009 03:52:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751343AbZGBDv4 (ORCPT ); Wed, 1 Jul 2009 23:51:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751652AbZGBDv4 (ORCPT ); Wed, 1 Jul 2009 23:51:56 -0400 Received: from marcansoft.com ([80.68.93.119]:41982 "EHLO smtp.marcansoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751343AbZGBDvz (ORCPT ); Wed, 1 Jul 2009 23:51:55 -0400 Received: from [192.168.3.171] (85.Red-88-24-251.staticIP.rima-tde.net [88.24.251.85]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.marcansoft.com (Postfix) with ESMTPSA id 9419965247; Thu, 2 Jul 2009 05:51:57 +0200 (CEST) Message-ID: <4A4C2EDC.6070209@marcansoft.com> Date: Thu, 02 Jul 2009 05:51:56 +0200 From: Hector Martin User-Agent: Thunderbird 2.0.0.21 (X11/20090530) MIME-Version: 1.0 To: Andrew Morton CC: astarikovskiy@suse.de, lenb@kernel.org, linux-acpi@vger.kernel.org Subject: Re: [PATCH] Work around negative s16 battery current on Acer References: <4A4BA8F9.9070803@marcansoft.com> <20090701112958.1d24e06f.akpm@linux-foundation.org> In-Reply-To: <20090701112958.1d24e06f.akpm@linux-foundation.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Andrew Morton wrote: > acpi_battery has no field `current_now' in 2.6.30 or 2.6.31-rc1. Which > kernel version are you patching here? Updated patch for 2.6.30 attached. current_now got renamed to rate_now. --- linux-2.6.30-gentoo-r1/drivers/acpi/battery.c.old 2009-07-02 04:04:52.000000000 +0200 +++ linux-2.6.30-gentoo-r1/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