Skip to content

Commit

Permalink
ACPI / Battery: Update information on info notification and resume
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rafael J. Wysocki authored and Len Brown committed Jan 12, 2011
1 parent d57d09a commit da8aeb9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/acpi/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,17 @@ static int acpi_battery_update(struct acpi_battery *battery)
return result;
}

static void acpi_battery_refresh(struct acpi_battery *battery)
{
if (!battery->bat.dev)
return;

acpi_battery_get_info(battery);
/* The battery may have changed its reporting units. */
sysfs_remove_battery(battery);
sysfs_add_battery(battery);
}

/* --------------------------------------------------------------------------
FS Interface (/proc)
-------------------------------------------------------------------------- */
Expand Down Expand Up @@ -916,6 +927,8 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event)
if (!battery)
return;
old = battery->bat.dev;
if (event == ACPI_BATTERY_NOTIFY_INFO)
acpi_battery_refresh(battery);
acpi_battery_update(battery);
acpi_bus_generate_proc_event(device, event,
acpi_battery_present(battery));
Expand Down Expand Up @@ -985,6 +998,7 @@ static int acpi_battery_resume(struct acpi_device *device)
if (!device)
return -EINVAL;
battery = acpi_driver_data(device);
acpi_battery_refresh(battery);
battery->update_time = 0;
acpi_battery_update(battery);
return 0;
Expand Down

0 comments on commit da8aeb9

Please sign in to comment.