toshiba-wmi.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * toshiba_wmi.c - Toshiba WMI Hotkey Driver
  3. *
  4. * Copyright (C) 2015 Azael Avalos <coproscefalo@gmail.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. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/types.h>
  22. #include <linux/acpi.h>
  23. #include <linux/input.h>
  24. #include <linux/input/sparse-keymap.h>
  25. MODULE_AUTHOR("Azael Avalos");
  26. MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
  27. MODULE_LICENSE("GPL");
  28. #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  29. MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID);
  30. static struct input_dev *toshiba_wmi_input_dev;
  31. static const struct key_entry toshiba_wmi_keymap[] __initconst = {
  32. /* TODO: Add keymap values once found... */
  33. /*{ KE_KEY, 0x00, { KEY_ } },*/
  34. { KE_END, 0 }
  35. };
  36. static void toshiba_wmi_notify(u32 value, void *context)
  37. {
  38. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  39. union acpi_object *obj;
  40. acpi_status status;
  41. status = wmi_get_event_data(value, &response);
  42. if (ACPI_FAILURE(status)) {
  43. pr_err("Bad event status 0x%x\n", status);
  44. return;
  45. }
  46. obj = (union acpi_object *)response.pointer;
  47. if (!obj)
  48. return;
  49. /* TODO: Add proper checks once we have data */
  50. pr_debug("Unknown event received, obj type %x\n", obj->type);
  51. kfree(response.pointer);
  52. }
  53. static int __init toshiba_wmi_input_setup(void)
  54. {
  55. acpi_status status;
  56. int err;
  57. toshiba_wmi_input_dev = input_allocate_device();
  58. if (!toshiba_wmi_input_dev)
  59. return -ENOMEM;
  60. toshiba_wmi_input_dev->name = "Toshiba WMI hotkeys";
  61. toshiba_wmi_input_dev->phys = "wmi/input0";
  62. toshiba_wmi_input_dev->id.bustype = BUS_HOST;
  63. err = sparse_keymap_setup(toshiba_wmi_input_dev,
  64. toshiba_wmi_keymap, NULL);
  65. if (err)
  66. goto err_free_dev;
  67. status = wmi_install_notify_handler(TOSHIBA_WMI_EVENT_GUID,
  68. toshiba_wmi_notify, NULL);
  69. if (ACPI_FAILURE(status)) {
  70. err = -EIO;
  71. goto err_free_keymap;
  72. }
  73. err = input_register_device(toshiba_wmi_input_dev);
  74. if (err)
  75. goto err_remove_notifier;
  76. return 0;
  77. err_remove_notifier:
  78. wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
  79. err_free_keymap:
  80. sparse_keymap_free(toshiba_wmi_input_dev);
  81. err_free_dev:
  82. input_free_device(toshiba_wmi_input_dev);
  83. return err;
  84. }
  85. static void toshiba_wmi_input_destroy(void)
  86. {
  87. wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
  88. sparse_keymap_free(toshiba_wmi_input_dev);
  89. input_unregister_device(toshiba_wmi_input_dev);
  90. }
  91. static int __init toshiba_wmi_init(void)
  92. {
  93. int ret;
  94. if (!wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  95. return -ENODEV;
  96. ret = toshiba_wmi_input_setup();
  97. if (ret) {
  98. pr_err("Failed to setup input device\n");
  99. return ret;
  100. }
  101. pr_info("Toshiba WMI Hotkey Driver\n");
  102. return 0;
  103. }
  104. static void __exit toshiba_wmi_exit(void)
  105. {
  106. if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  107. toshiba_wmi_input_destroy();
  108. }
  109. module_init(toshiba_wmi_init);
  110. module_exit(toshiba_wmi_exit);