]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86: lenovo-wmi-helpers: Add helper for creating per-device debugfs dir
authorRong Zhang <i@rong.moe>
Wed, 20 May 2026 06:07:39 +0000 (06:07 +0000)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 28 May 2026 11:17:48 +0000 (14:17 +0300)
We are about to add debugfs support for lenovo-wmi-capdata. Let's setup
a debugfs directory called "lenovo_wmi" for tidiness, so that any
lenovo-wmi-* device can put its subdirectory under the directory.
Subdirectories will be named after the corresponding WMI devices.

Signed-off-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
Link: https://patch.msgid.link/20260520060740.119554-7-derekjohn.clark@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/lenovo/wmi-helpers.c
drivers/platform/x86/lenovo/wmi-helpers.h

index 7a198259e3933c9330c3746a1c1f0b3e3cc1eef2..8f5766c391eb4d465865cb84de8e36ac74b7e735 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <linux/acpi.h>
 #include <linux/cleanup.h>
+#include <linux/debugfs.h>
+#include <linux/device.h>
 #include <linux/errno.h>
 #include <linux/export.h>
 #include <linux/module.h>
@@ -185,6 +187,38 @@ int lwmi_tm_notifier_call(enum thermal_mode *mode)
 }
 EXPORT_SYMBOL_NS_GPL(lwmi_tm_notifier_call, "LENOVO_WMI_HELPERS");
 
+static struct dentry *lwmi_debugfs_dir;
+
+/**
+ * lwmi_debugfs_create_dir() - Helper function for creating a debugfs directory
+ * for a device.
+ * @wdev: Pointer to the WMI device to be called.
+ *
+ * Caller must remove the directory with debugfs_remove_recursive() on device
+ * removal.
+ *
+ * Return: Pointer to the created directory.
+ */
+struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev)
+{
+       return debugfs_create_dir(dev_name(&wdev->dev), lwmi_debugfs_dir);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_debugfs_create_dir, "LENOVO_WMI_HELPERS");
+
+static int __init lwmi_helpers_init(void)
+{
+       lwmi_debugfs_dir = debugfs_create_dir("lenovo_wmi", NULL);
+
+       return 0;
+}
+subsys_initcall(lwmi_helpers_init)
+
+static void __exit lwmi_helpers_exit(void)
+{
+       debugfs_remove_recursive(lwmi_debugfs_dir);
+}
+module_exit(lwmi_helpers_exit)
+
 MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
 MODULE_DESCRIPTION("Lenovo WMI Helpers Driver");
 MODULE_LICENSE("GPL");
index ed7db3ebba6cc1fefa6a2ced81c0db29558871e2..039fe61003ceb9196835b64fce519f91b349c62a 100644 (file)
@@ -16,6 +16,8 @@ struct wmi_method_args_32 {
        u32 arg1;
 };
 
+struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev);
+
 enum lwmi_event_type {
        LWMI_GZ_GET_THERMAL_MODE = 0x01,
 };