Skip to content

Commit ff1d7ae

Browse files
committed
ACPI: tiny-power-button: Eliminate the driver notify callback
Rework the ACPI tiny-power-button driver to install a notify handler or a fixed event handler for the device it binds to by itself and drop its notify callback. This will allow acpi_device_install_notify_handler() and acpi_device_remove_notify_handler() to be simplified going forward. Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e4e62d5 commit ff1d7ae

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

drivers/acpi/tiny-power-button.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,61 @@ static const struct acpi_device_id tiny_power_button_device_ids[] = {
1919
};
2020
MODULE_DEVICE_TABLE(acpi, tiny_power_button_device_ids);
2121

22-
static int acpi_noop_add(struct acpi_device *device)
22+
static void acpi_tiny_power_button_notify(acpi_handle handle, u32 event, void *data)
2323
{
24-
return 0;
24+
kill_cad_pid(power_signal, 1);
2525
}
2626

27-
static void acpi_noop_remove(struct acpi_device *device)
27+
static void acpi_tiny_power_button_notify_run(void *not_used)
2828
{
29+
acpi_tiny_power_button_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, NULL);
2930
}
3031

31-
static void acpi_tiny_power_button_notify(struct acpi_device *device, u32 event)
32+
static u32 acpi_tiny_power_button_event(void *not_used)
3233
{
33-
kill_cad_pid(power_signal, 1);
34+
acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_tiny_power_button_notify_run, NULL);
35+
return ACPI_INTERRUPT_HANDLED;
36+
}
37+
38+
static int acpi_tiny_power_button_add(struct acpi_device *device)
39+
{
40+
acpi_status status;
41+
42+
if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) {
43+
status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
44+
acpi_tiny_power_button_event,
45+
NULL);
46+
} else {
47+
status = acpi_install_notify_handler(device->handle,
48+
ACPI_DEVICE_NOTIFY,
49+
acpi_tiny_power_button_notify,
50+
NULL);
51+
}
52+
if (ACPI_FAILURE(status))
53+
return -ENODEV;
54+
55+
return 0;
56+
}
57+
58+
static void acpi_tiny_power_button_remove(struct acpi_device *device)
59+
{
60+
if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) {
61+
acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
62+
acpi_tiny_power_button_event);
63+
} else {
64+
acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
65+
acpi_tiny_power_button_notify);
66+
}
67+
acpi_os_wait_events_complete();
3468
}
3569

3670
static struct acpi_driver acpi_tiny_power_button_driver = {
3771
.name = "tiny-power-button",
3872
.class = "tiny-power-button",
3973
.ids = tiny_power_button_device_ids,
4074
.ops = {
41-
.add = acpi_noop_add,
42-
.remove = acpi_noop_remove,
43-
.notify = acpi_tiny_power_button_notify,
75+
.add = acpi_tiny_power_button_add,
76+
.remove = acpi_tiny_power_button_remove,
4477
},
4578
};
4679

0 commit comments

Comments
 (0)