diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2011-01-06 17:42:27 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2011-01-12 05:06:10 -0500 |
commit | da8aeb92d4853f37e281f11fddf61f9c7d84c3cd (patch) | |
tree | 784dda3d8ce144a6b79fbace9a6223568b0031d4 | |
parent | d57d09a480e1db38eeee7629c81289b00f338a15 (diff) |
ACPI / Battery: Update information on info notification and resume
A notification event 0x81 from an ACPI battery device requires us to
re-read the battery information structure. Follow this requirement
and remove and re-create the battery's attibutes in sysfs so that
they reflect the reporting units used by the battery at the moment
(those units may actually change sometimes at run time, which happens
on some Thinkpads).
The approach used in this patch was suggested by Matthew Garrett.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Reported-by: Matthew Garrett <mjg@redhat.com>
Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r-- | drivers/acpi/battery.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 2a31421e0d75..68bc227e7c4c 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -631,6 +631,17 @@ static int acpi_battery_update(struct acpi_battery *battery) | |||
631 | return result; | 631 | return result; |
632 | } | 632 | } |
633 | 633 | ||
634 | static void acpi_battery_refresh(struct acpi_battery *battery) | ||
635 | { | ||
636 | if (!battery->bat.dev) | ||
637 | return; | ||
638 | |||
639 | acpi_battery_get_info(battery); | ||
640 | /* The battery may have changed its reporting units. */ | ||
641 | sysfs_remove_battery(battery); | ||
642 | sysfs_add_battery(battery); | ||
643 | } | ||
644 | |||
634 | /* -------------------------------------------------------------------------- | 645 | /* -------------------------------------------------------------------------- |
635 | FS Interface (/proc) | 646 | FS Interface (/proc) |
636 | -------------------------------------------------------------------------- */ | 647 | -------------------------------------------------------------------------- */ |
@@ -916,6 +927,8 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event) | |||
916 | if (!battery) | 927 | if (!battery) |
917 | return; | 928 | return; |
918 | old = battery->bat.dev; | 929 | old = battery->bat.dev; |
930 | if (event == ACPI_BATTERY_NOTIFY_INFO) | ||
931 | acpi_battery_refresh(battery); | ||
919 | acpi_battery_update(battery); | 932 | acpi_battery_update(battery); |
920 | acpi_bus_generate_proc_event(device, event, | 933 | acpi_bus_generate_proc_event(device, event, |
921 | acpi_battery_present(battery)); | 934 | acpi_battery_present(battery)); |
@@ -985,6 +998,7 @@ static int acpi_battery_resume(struct acpi_device *device) | |||
985 | if (!device) | 998 | if (!device) |
986 | return -EINVAL; | 999 | return -EINVAL; |
987 | battery = acpi_driver_data(device); | 1000 | battery = acpi_driver_data(device); |
1001 | acpi_battery_refresh(battery); | ||
988 | battery->update_time = 0; | 1002 | battery->update_time = 0; |
989 | acpi_battery_update(battery); | 1003 | acpi_battery_update(battery); |
990 | return 0; | 1004 | return 0; |