[kernel] Snipe ACPI patch from mjg59 to fix battery levels on some laptops

Kyle McMartin kyle at fedoraproject.org
Thu Sep 23 16:27:53 UTC 2010


commit 6406b98a0e3692eba8739976e7143363c5cc394c
Author: Kyle McMartin <kyle at dreadnought.i.jkkm.org>
Date:   Thu Sep 23 11:16:03 2010 -0400

    Snipe ACPI patch from mjg59 to fix battery levels on some laptops

 ...-battery-information-on-notification-0x81.patch |   96 ++++++++++++++++++++
 kernel.spec                                        |    7 ++-
 2 files changed, 102 insertions(+), 1 deletions(-)
---
diff --git a/acpi-update-battery-information-on-notification-0x81.patch b/acpi-update-battery-information-on-notification-0x81.patch
new file mode 100644
index 0000000..5fe34b9
--- /dev/null
+++ b/acpi-update-battery-information-on-notification-0x81.patch
@@ -0,0 +1,96 @@
+From kyle at infradead.org Wed Sep 22 18:35:38 2010
+From: Matthew Garrett <mjg at redhat.com>
+To: linux-acpi at vger.kernel.org
+Cc: linux-kernel at vger.kernel.org, Matthew Garrett <mjg at redhat.com>
+Subject: [PATCH] acpi: Update battery information on notification 0x81
+Date: 	Mon, 16 Aug 2010 16:32:19 -0400
+
+A notification event 0x81 from an ACPI battery device requires us to
+re-read the battery information structure. Do so, and if the battery's
+reporting units have changed (as is the case on some Thinkpads) destroy
+and recreate the battery in order to populate the fields correctly.
+
+Signed-off-by: Matthew Garrett <mjg at redhat.com>
+---
+ drivers/acpi/battery.c |   22 +++++++++++++++++-----
+ 1 files changed, 17 insertions(+), 5 deletions(-)
+
+diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
+index dc58402..69638c4 100644
+--- a/drivers/acpi/battery.c
++++ b/drivers/acpi/battery.c
+@@ -562,9 +562,10 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
+ 	}
+ }
+ 
+-static int acpi_battery_update(struct acpi_battery *battery)
++static int acpi_battery_update(struct acpi_battery *battery, bool get_info)
+ {
+ 	int result, old_present = acpi_battery_present(battery);
++	int old_power_unit = battery->power_unit;
+ 	result = acpi_battery_get_status(battery);
+ 	if (result)
+ 		return result;
+@@ -587,6 +588,16 @@ static int acpi_battery_update(struct acpi_battery *battery)
+ 	if (!battery->bat.dev)
+ 		sysfs_add_battery(battery);
+ #endif
++	if (get_info) {
++		acpi_battery_get_info(battery);
++#ifdef CONFIG_ACPI_SYSFS_POWER
++		if (old_power_unit != battery->power_unit) {
++			/* The battery has changed its reporting units */
++			sysfs_remove_battery(battery);
++			sysfs_add_battery(battery);
++		}
++#endif
++	}
+ 	return acpi_battery_get_state(battery);
+ }
+ 
+@@ -762,7 +773,7 @@ static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
+ static int acpi_battery_read(int fid, struct seq_file *seq)
+ {
+ 	struct acpi_battery *battery = seq->private;
+-	int result = acpi_battery_update(battery);
++	int result = acpi_battery_update(battery, false);
+ 	return acpi_print_funcs[fid](seq, result);
+ }
+ 
+@@ -877,7 +888,8 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event)
+ #ifdef CONFIG_ACPI_SYSFS_POWER
+ 	old = battery->bat.dev;
+ #endif
+-	acpi_battery_update(battery);
++	acpi_battery_update(battery, (event == ACPI_BATTERY_NOTIFY_INFO ? true
++				      : false));
+ 	acpi_bus_generate_proc_event(device, event,
+ 				     acpi_battery_present(battery));
+ 	acpi_bus_generate_netlink_event(device->pnp.device_class,
+@@ -908,7 +920,7 @@ static int acpi_battery_add(struct acpi_device *device)
+ 	if (ACPI_SUCCESS(acpi_get_handle(battery->device->handle,
+ 			"_BIX", &handle)))
+ 		set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
+-	acpi_battery_update(battery);
++	acpi_battery_update(battery, false);
+ #ifdef CONFIG_ACPI_PROCFS_POWER
+ 	result = acpi_battery_add_fs(device);
+ #endif
+@@ -951,7 +963,7 @@ static int acpi_battery_resume(struct acpi_device *device)
+ 		return -EINVAL;
+ 	battery = acpi_driver_data(device);
+ 	battery->update_time = 0;
+-	acpi_battery_update(battery);
++	acpi_battery_update(battery, true);
+ 	return 0;
+ }
+ 
+-- 
+1.7.2.1
+
+--
+To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
+the body of a message to majordomo at vger.kernel.org
+More majordomo info at  http://vger.kernel.org/majordomo-info.html
+Please read the FAQ at  http://www.tux.org/lkml/
+
diff --git a/kernel.spec b/kernel.spec
index 5b606d5..38c505e 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -51,7 +51,7 @@ Summary: The Linux kernel
 # For non-released -rc kernels, this will be prepended with "0.", so
 # for example a 3 here will become 0.3
 #
-%global baserelease 24
+%global baserelease 25
 %global fedora_build %{baserelease}
 
 # base_sublevel is the kernel version we're starting with and patching
@@ -625,6 +625,7 @@ Patch390: linux-2.6-defaults-acpi-video.patch
 Patch391: linux-2.6-acpi-video-dos.patch
 Patch393: acpi-ec-add-delay-before-write.patch
 Patch394: linux-2.6-acpi-debug-infinite-loop.patch
+Patch395: acpi-update-battery-information-on-notification-0x81.patch
 
 Patch450: linux-2.6-input-kill-stupid-messages.patch
 Patch452: linux-2.6.30-no-pcspkr-modalias.patch
@@ -1185,6 +1186,7 @@ ApplyPatch linux-2.6-defaults-acpi-video.patch
 ApplyPatch linux-2.6-acpi-video-dos.patch
 ApplyPatch acpi-ec-add-delay-before-write.patch
 ApplyPatch linux-2.6-acpi-debug-infinite-loop.patch
+ApplyPatch acpi-update-battery-information-on-notification-0x81.patch
 
 # Various low-impact patches to aid debugging.
 ApplyPatch linux-2.6-debug-sizeof-structs.patch
@@ -1920,6 +1922,9 @@ fi
 #                 ||     ||
 
 %changelog
+* Thu Sep 23 2010 Kyle McMartin <kyle at redhat.com> 2.6.36-0.25.rc5
+- Snipe ACPI patch from mjg59 to fix battery levels on some laptops.
+
 * Tue Sep 21 2010 Kyle McMartin <kyle at redhat.com>
 - Add new btusb ids for MacBookPro from wwoods at .
 


More information about the scm-commits mailing list