Skip to content

Commit

Permalink
ACPI: AC: Install Notify() handler directly
Browse files Browse the repository at this point in the history
Modify the ACPI AC 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 AC driver to be switched over to a platform one in the
future.

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 0d16710 commit 543a2d1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions drivers/acpi/ac.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MODULE_LICENSE("GPL");

static int acpi_ac_add(struct acpi_device *device);
static void acpi_ac_remove(struct acpi_device *device);
static void acpi_ac_notify(struct acpi_device *device, u32 event);
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data);

static const struct acpi_device_id ac_device_ids[] = {
{"ACPI0003", 0},
Expand All @@ -54,11 +54,9 @@ static struct acpi_driver acpi_ac_driver = {
.name = "ac",
.class = ACPI_AC_CLASS,
.ids = ac_device_ids,
.flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
.ops = {
.add = acpi_ac_add,
.remove = acpi_ac_remove,
.notify = acpi_ac_notify,
},
.drv.pm = &acpi_ac_pm,
};
Expand Down Expand Up @@ -128,8 +126,9 @@ static enum power_supply_property ac_props[] = {
};

/* Driver Model */
static void acpi_ac_notify(struct acpi_device *device, u32 event)
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
{
struct acpi_device *device = data;
struct acpi_ac *ac = acpi_driver_data(device);

if (!ac)
Expand Down Expand Up @@ -235,7 +234,7 @@ static int acpi_ac_add(struct acpi_device *device)

result = acpi_ac_get_state(ac);
if (result)
goto end;
goto err_release_ac;

psy_cfg.drv_data = ac;

Expand All @@ -248,17 +247,27 @@ static int acpi_ac_add(struct acpi_device *device)
&ac->charger_desc, &psy_cfg);
if (IS_ERR(ac->charger)) {
result = PTR_ERR(ac->charger);
goto end;
goto err_release_ac;
}

pr_info("%s [%s] (%s)\n", acpi_device_name(device),
acpi_device_bid(device), ac->state ? "on-line" : "off-line");

ac->battery_nb.notifier_call = acpi_ac_battery_notify;
register_acpi_notifier(&ac->battery_nb);
end:

result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
acpi_ac_notify);
if (result)
kfree(ac);
goto err_unregister;

return 0;

err_unregister:
power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);
err_release_ac:
kfree(ac);

return result;
}
Expand Down Expand Up @@ -297,6 +306,8 @@ static void acpi_ac_remove(struct acpi_device *device)

ac = acpi_driver_data(device);

acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
acpi_ac_notify);
power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);

Expand Down

0 comments on commit 543a2d1

Please sign in to comment.