uniwill-wmi.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Linux hotkey driver for Uniwill notebooks.
  4. *
  5. * Special thanks go to Pőcze Barnabás, Christoffer Sandberg and Werner Sembach
  6. * for supporting the development of this driver either through prior work or
  7. * by answering questions regarding the underlying WMI interface.
  8. *
  9. * Copyright (C) 2025 Armin Wolf <W_Armin@gmx.de>
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/acpi.h>
  13. #include <linux/device.h>
  14. #include <linux/init.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/notifier.h>
  17. #include <linux/printk.h>
  18. #include <linux/types.h>
  19. #include <linux/wmi.h>
  20. #include "uniwill-wmi.h"
  21. #define DRIVER_NAME "uniwill-wmi"
  22. #define UNIWILL_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
  23. static BLOCKING_NOTIFIER_HEAD(uniwill_wmi_chain_head);
  24. static void devm_uniwill_wmi_unregister_notifier(void *data)
  25. {
  26. struct notifier_block *nb = data;
  27. blocking_notifier_chain_unregister(&uniwill_wmi_chain_head, nb);
  28. }
  29. int devm_uniwill_wmi_register_notifier(struct device *dev, struct notifier_block *nb)
  30. {
  31. int ret;
  32. ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
  33. if (ret < 0)
  34. return ret;
  35. return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
  36. }
  37. static void uniwill_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
  38. {
  39. u32 value;
  40. if (obj->type != ACPI_TYPE_INTEGER)
  41. return;
  42. value = obj->integer.value;
  43. dev_dbg(&wdev->dev, "Received WMI event %u\n", value);
  44. blocking_notifier_call_chain(&uniwill_wmi_chain_head, value, NULL);
  45. }
  46. /*
  47. * We cannot fully trust this GUID since Uniwill just copied the WMI GUID
  48. * from the Windows driver example, and others probably did the same.
  49. *
  50. * Because of this we cannot use this WMI GUID for autoloading. Instead the
  51. * associated driver will be registered manually after matching a DMI table.
  52. */
  53. static const struct wmi_device_id uniwill_wmi_id_table[] = {
  54. { UNIWILL_EVENT_GUID, NULL },
  55. { }
  56. };
  57. static struct wmi_driver uniwill_wmi_driver = {
  58. .driver = {
  59. .name = DRIVER_NAME,
  60. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  61. },
  62. .id_table = uniwill_wmi_id_table,
  63. .notify = uniwill_wmi_notify,
  64. .no_singleton = true,
  65. };
  66. int __init uniwill_wmi_register_driver(void)
  67. {
  68. return wmi_driver_register(&uniwill_wmi_driver);
  69. }
  70. void __exit uniwill_wmi_unregister_driver(void)
  71. {
  72. wmi_driver_unregister(&uniwill_wmi_driver);
  73. }