hp-wireless.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Airplane mode button for HP & Xiaomi laptops
  3. *
  4. * Copyright (C) 2014-2017 Alex Hung <alex.hung@canonical.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/input.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/acpi.h>
  26. #include <acpi/acpi_bus.h>
  27. MODULE_LICENSE("GPL");
  28. MODULE_AUTHOR("Alex Hung");
  29. MODULE_ALIAS("acpi*:HPQ6001:*");
  30. MODULE_ALIAS("acpi*:WSTADEF:*");
  31. static struct input_dev *hpwl_input_dev;
  32. static const struct acpi_device_id hpwl_ids[] = {
  33. {"HPQ6001", 0},
  34. {"WSTADEF", 0},
  35. {"", 0},
  36. };
  37. static int hp_wireless_input_setup(void)
  38. {
  39. int err;
  40. hpwl_input_dev = input_allocate_device();
  41. if (!hpwl_input_dev)
  42. return -ENOMEM;
  43. hpwl_input_dev->name = "HP Wireless hotkeys";
  44. hpwl_input_dev->phys = "hpq6001/input0";
  45. hpwl_input_dev->id.bustype = BUS_HOST;
  46. hpwl_input_dev->evbit[0] = BIT(EV_KEY);
  47. set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
  48. err = input_register_device(hpwl_input_dev);
  49. if (err)
  50. goto err_free_dev;
  51. return 0;
  52. err_free_dev:
  53. input_free_device(hpwl_input_dev);
  54. return err;
  55. }
  56. static void hp_wireless_input_destroy(void)
  57. {
  58. input_unregister_device(hpwl_input_dev);
  59. }
  60. static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
  61. {
  62. if (event != 0x80) {
  63. pr_info("Received unknown event (0x%x)\n", event);
  64. return;
  65. }
  66. input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
  67. input_sync(hpwl_input_dev);
  68. input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
  69. input_sync(hpwl_input_dev);
  70. }
  71. static int hpwl_add(struct acpi_device *device)
  72. {
  73. int err;
  74. err = hp_wireless_input_setup();
  75. if (err)
  76. pr_err("Failed to setup hp wireless hotkeys\n");
  77. return err;
  78. }
  79. static int hpwl_remove(struct acpi_device *device)
  80. {
  81. hp_wireless_input_destroy();
  82. return 0;
  83. }
  84. static struct acpi_driver hpwl_driver = {
  85. .name = "hp-wireless",
  86. .owner = THIS_MODULE,
  87. .ids = hpwl_ids,
  88. .ops = {
  89. .add = hpwl_add,
  90. .remove = hpwl_remove,
  91. .notify = hpwl_notify,
  92. },
  93. };
  94. module_acpi_driver(hpwl_driver);