toshiba-wmi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * toshiba_wmi.c - Toshiba WMI Hotkey Driver
  4. *
  5. * Copyright (C) 2015 Azael Avalos <coproscefalo@gmail.com>
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/types.h>
  12. #include <linux/acpi.h>
  13. #include <linux/input.h>
  14. #include <linux/input/sparse-keymap.h>
  15. #include <linux/dmi.h>
  16. MODULE_AUTHOR("Azael Avalos");
  17. MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
  18. MODULE_LICENSE("GPL");
  19. #define WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  20. MODULE_ALIAS("wmi:"WMI_EVENT_GUID);
  21. static struct input_dev *toshiba_wmi_input_dev;
  22. static const struct key_entry toshiba_wmi_keymap[] __initconst = {
  23. /* TODO: Add keymap values once found... */
  24. /*{ KE_KEY, 0x00, { KEY_ } },*/
  25. { KE_END, 0 }
  26. };
  27. static void toshiba_wmi_notify(u32 value, void *context)
  28. {
  29. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  30. union acpi_object *obj;
  31. acpi_status status;
  32. status = wmi_get_event_data(value, &response);
  33. if (ACPI_FAILURE(status)) {
  34. pr_err("Bad event status 0x%x\n", status);
  35. return;
  36. }
  37. obj = (union acpi_object *)response.pointer;
  38. if (!obj)
  39. return;
  40. /* TODO: Add proper checks once we have data */
  41. pr_debug("Unknown event received, obj type %x\n", obj->type);
  42. kfree(response.pointer);
  43. }
  44. static const struct dmi_system_id toshiba_wmi_dmi_table[] __initconst = {
  45. {
  46. .ident = "Toshiba laptop",
  47. .matches = {
  48. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  49. },
  50. },
  51. {}
  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(WMI_EVENT_GUID,
  68. toshiba_wmi_notify, NULL);
  69. if (ACPI_FAILURE(status)) {
  70. err = -EIO;
  71. goto err_free_dev;
  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(WMI_EVENT_GUID);
  79. err_free_dev:
  80. input_free_device(toshiba_wmi_input_dev);
  81. return err;
  82. }
  83. static void toshiba_wmi_input_destroy(void)
  84. {
  85. wmi_remove_notify_handler(WMI_EVENT_GUID);
  86. input_unregister_device(toshiba_wmi_input_dev);
  87. }
  88. static int __init toshiba_wmi_init(void)
  89. {
  90. int ret;
  91. if (!wmi_has_guid(WMI_EVENT_GUID) ||
  92. !dmi_check_system(toshiba_wmi_dmi_table))
  93. return -ENODEV;
  94. ret = toshiba_wmi_input_setup();
  95. if (ret) {
  96. pr_err("Failed to setup input device\n");
  97. return ret;
  98. }
  99. pr_info("Toshiba WMI Hotkey Driver\n");
  100. return 0;
  101. }
  102. static void __exit toshiba_wmi_exit(void)
  103. {
  104. if (wmi_has_guid(WMI_EVENT_GUID))
  105. toshiba_wmi_input_destroy();
  106. }
  107. module_init(toshiba_wmi_init);
  108. module_exit(toshiba_wmi_exit);