xref: /linux/drivers/acpi/tiny-power-button.c (revision 97884ca8c2925d14c32188e865069f21378b4b4f)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #include <linux/module.h>
3 #include <linux/sched/signal.h>
4 #include <linux/acpi.h>
5 #include <acpi/button.h>
6 
7 ACPI_MODULE_NAME("tiny-power-button");
8 MODULE_AUTHOR("Josh Triplett");
9 MODULE_DESCRIPTION("ACPI Tiny Power Button Driver");
10 MODULE_LICENSE("GPL");
11 
12 static int power_signal __read_mostly = CONFIG_ACPI_TINY_POWER_BUTTON_SIGNAL;
13 module_param(power_signal, int, 0644);
14 MODULE_PARM_DESC(power_signal, "Power button sends this signal to init");
15 
16 static const struct acpi_device_id tiny_power_button_device_ids[] = {
17 	{ ACPI_BUTTON_HID_POWER, 0 },
18 	{ ACPI_BUTTON_HID_POWERF, 0 },
19 	{ "", 0 },
20 };
21 MODULE_DEVICE_TABLE(acpi, tiny_power_button_device_ids);
22 
23 static int acpi_noop_add_remove(struct acpi_device *device)
24 {
25 	return 0;
26 }
27 
28 static void acpi_tiny_power_button_notify(struct acpi_device *device, u32 event)
29 {
30 	kill_cad_pid(power_signal, 1);
31 }
32 
33 static struct acpi_driver acpi_tiny_power_button_driver = {
34 	.name = "tiny-power-button",
35 	.class = "tiny-power-button",
36 	.ids = tiny_power_button_device_ids,
37 	.ops = {
38 		.add = acpi_noop_add_remove,
39 		.remove = acpi_noop_add_remove,
40 		.notify = acpi_tiny_power_button_notify,
41 	},
42 };
43 
44 module_driver(acpi_tiny_power_button_driver,
45 		acpi_bus_register_driver,
46 		acpi_bus_unregister_driver);
47