tiny-power-button.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. MODULE_AUTHOR("Josh Triplett");
  7. MODULE_DESCRIPTION("ACPI Tiny Power Button Driver");
  8. MODULE_LICENSE("GPL");
  9. static int power_signal __read_mostly = CONFIG_ACPI_TINY_POWER_BUTTON_SIGNAL;
  10. module_param(power_signal, int, 0644);
  11. MODULE_PARM_DESC(power_signal, "Power button sends this signal to init");
  12. static const struct acpi_device_id tiny_power_button_device_ids[] = {
  13. { ACPI_BUTTON_HID_POWER, 0 },
  14. { ACPI_BUTTON_HID_POWERF, 0 },
  15. { "", 0 },
  16. };
  17. MODULE_DEVICE_TABLE(acpi, tiny_power_button_device_ids);
  18. static int acpi_noop_add_remove(struct acpi_device *device)
  19. {
  20. return 0;
  21. }
  22. static void acpi_tiny_power_button_notify(struct acpi_device *device, u32 event)
  23. {
  24. kill_cad_pid(power_signal, 1);
  25. }
  26. static struct acpi_driver acpi_tiny_power_button_driver = {
  27. .name = "tiny-power-button",
  28. .class = "tiny-power-button",
  29. .ids = tiny_power_button_device_ids,
  30. .ops = {
  31. .add = acpi_noop_add_remove,
  32. .remove = acpi_noop_add_remove,
  33. .notify = acpi_tiny_power_button_notify,
  34. },
  35. };
  36. module_acpi_driver(acpi_tiny_power_button_driver);