hp-wireless.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * hp-wireless button for Windows 8
  3. *
  4. * Copyright (C) 2014 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. static struct input_dev *hpwl_input_dev;
  31. static const struct acpi_device_id hpwl_ids[] = {
  32. {"HPQ6001", 0},
  33. {"", 0},
  34. };
  35. static int hp_wireless_input_setup(void)
  36. {
  37. int err;
  38. hpwl_input_dev = input_allocate_device();
  39. if (!hpwl_input_dev)
  40. return -ENOMEM;
  41. hpwl_input_dev->name = "HP Wireless hotkeys";
  42. hpwl_input_dev->phys = "hpq6001/input0";
  43. hpwl_input_dev->id.bustype = BUS_HOST;
  44. hpwl_input_dev->evbit[0] = BIT(EV_KEY);
  45. set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
  46. err = input_register_device(hpwl_input_dev);
  47. if (err)
  48. goto err_free_dev;
  49. return 0;
  50. err_free_dev:
  51. input_free_device(hpwl_input_dev);
  52. return err;
  53. }
  54. static void hp_wireless_input_destroy(void)
  55. {
  56. input_unregister_device(hpwl_input_dev);
  57. }
  58. static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
  59. {
  60. if (event != 0x80) {
  61. pr_info("Received unknown event (0x%x)\n", event);
  62. return;
  63. }
  64. input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
  65. input_sync(hpwl_input_dev);
  66. input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
  67. input_sync(hpwl_input_dev);
  68. }
  69. static int hpwl_add(struct acpi_device *device)
  70. {
  71. int err;
  72. err = hp_wireless_input_setup();
  73. if (err)
  74. pr_err("Failed to setup hp wireless hotkeys\n");
  75. return err;
  76. }
  77. static int hpwl_remove(struct acpi_device *device)
  78. {
  79. hp_wireless_input_destroy();
  80. return 0;
  81. }
  82. static struct acpi_driver hpwl_driver = {
  83. .name = "hp-wireless",
  84. .owner = THIS_MODULE,
  85. .ids = hpwl_ids,
  86. .ops = {
  87. .add = hpwl_add,
  88. .remove = hpwl_remove,
  89. .notify = hpwl_notify,
  90. },
  91. };
  92. static int __init hpwl_init(void)
  93. {
  94. int err;
  95. pr_info("Initializing HPQ6001 module\n");
  96. err = acpi_bus_register_driver(&hpwl_driver);
  97. if (err)
  98. pr_err("Unable to register HP wireless control driver.\n");
  99. return err;
  100. }
  101. static void __exit hpwl_exit(void)
  102. {
  103. pr_info("Exiting HPQ6001 module\n");
  104. acpi_bus_unregister_driver(&hpwl_driver);
  105. }
  106. module_init(hpwl_init);
  107. module_exit(hpwl_exit);