Skip to content

Commit

Permalink
ACPI: battery: Install Notify() handler directly
Browse files Browse the repository at this point in the history
Modify the ACPI battery driver to install its own Notify() handler
directly instead of providing an ACPI driver .notify() callback.

This will allow the ACPI driver .notify() callback to be eliminated and
it will allow the battery driver to be switched over to a platform one
in the future.

While at it, fix up whitespaces in acpi_battery_remove().

Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
[ rjw: Subject and changelog edits, whitespace adjustments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Michal Wilczynski authored and Rafael J. Wysocki committed Jul 14, 2023
1 parent 6f70168 commit 1066625
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions drivers/acpi/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,9 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
}

/* Driver Interface */
static void acpi_battery_notify(struct acpi_device *device, u32 event)
static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
{
struct acpi_device *device = data;
struct acpi_battery *battery = acpi_driver_data(device);
struct power_supply *old;

Expand Down Expand Up @@ -1212,13 +1213,22 @@ static int acpi_battery_add(struct acpi_device *device)

device_init_wakeup(&device->dev, 1);

return result;
result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
acpi_battery_notify);
if (result)
goto fail_pm;

return 0;

fail_pm:
device_init_wakeup(&device->dev, 0);
unregister_pm_notifier(&battery->pm_nb);
fail:
sysfs_remove_battery(battery);
mutex_destroy(&battery->lock);
mutex_destroy(&battery->sysfs_lock);
kfree(battery);

return result;
}

Expand All @@ -1228,10 +1238,16 @@ static void acpi_battery_remove(struct acpi_device *device)

if (!device || !acpi_driver_data(device))
return;
device_init_wakeup(&device->dev, 0);

battery = acpi_driver_data(device);

acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
acpi_battery_notify);

device_init_wakeup(&device->dev, 0);
unregister_pm_notifier(&battery->pm_nb);
sysfs_remove_battery(battery);

mutex_destroy(&battery->lock);
mutex_destroy(&battery->sysfs_lock);
kfree(battery);
Expand Down Expand Up @@ -1264,11 +1280,9 @@ static struct acpi_driver acpi_battery_driver = {
.name = "battery",
.class = ACPI_BATTERY_CLASS,
.ids = battery_device_ids,
.flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
.ops = {
.add = acpi_battery_add,
.remove = acpi_battery_remove,
.notify = acpi_battery_notify,
},
.drv.pm = &acpi_battery_pm,
};
Expand Down

0 comments on commit 1066625

Please sign in to comment.