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