hp-wireless.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Airplane mode button for HP & Xiaomi laptops
  4. *
  5. * Copyright (C) 2014-2017 Alex Hung <alex.hung@canonical.com>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/input.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/acpi.h>
  13. #include <acpi/acpi_bus.h>
  14. MODULE_LICENSE("GPL");
  15. MODULE_AUTHOR("Alex Hung");
  16. MODULE_ALIAS("acpi*:HPQ6001:*");
  17. MODULE_ALIAS("acpi*:WSTADEF:*");
  18. MODULE_ALIAS("acpi*:AMDI0051:*");
  19. static struct input_dev *hpwl_input_dev;
  20. static const struct acpi_device_id hpwl_ids[] = {
  21. {"HPQ6001", 0},
  22. {"WSTADEF", 0},
  23. {"AMDI0051", 0},
  24. {"", 0},
  25. };
  26. static int hp_wireless_input_setup(void)
  27. {
  28. int err;
  29. hpwl_input_dev = input_allocate_device();
  30. if (!hpwl_input_dev)
  31. return -ENOMEM;
  32. hpwl_input_dev->name = "HP Wireless hotkeys";
  33. hpwl_input_dev->phys = "hpq6001/input0";
  34. hpwl_input_dev->id.bustype = BUS_HOST;
  35. hpwl_input_dev->evbit[0] = BIT(EV_KEY);
  36. set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
  37. err = input_register_device(hpwl_input_dev);
  38. if (err)
  39. goto err_free_dev;
  40. return 0;
  41. err_free_dev:
  42. input_free_device(hpwl_input_dev);
  43. return err;
  44. }
  45. static void hp_wireless_input_destroy(void)
  46. {
  47. input_unregister_device(hpwl_input_dev);
  48. }
  49. static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
  50. {
  51. if (event != 0x80) {
  52. pr_info("Received unknown event (0x%x)\n", event);
  53. return;
  54. }
  55. input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
  56. input_sync(hpwl_input_dev);
  57. input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
  58. input_sync(hpwl_input_dev);
  59. }
  60. static int hpwl_add(struct acpi_device *device)
  61. {
  62. int err;
  63. err = hp_wireless_input_setup();
  64. if (err)
  65. pr_err("Failed to setup hp wireless hotkeys\n");
  66. return err;
  67. }
  68. static int hpwl_remove(struct acpi_device *device)
  69. {
  70. hp_wireless_input_destroy();
  71. return 0;
  72. }
  73. static struct acpi_driver hpwl_driver = {
  74. .name = "hp-wireless",
  75. .owner = THIS_MODULE,
  76. .ids = hpwl_ids,
  77. .ops = {
  78. .add = hpwl_add,
  79. .remove = hpwl_remove,
  80. .notify = hpwl_notify,
  81. },
  82. };
  83. module_acpi_driver(hpwl_driver);