toshiba-wmi.c 3.5 KB

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