Skip to content

Commit 8d4bbf9

Browse files
Rongronggg91Naim
authored andcommitted
platform/x86: lenovo-wmi-helpers: Add helper for creating per-device debugfs dir
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>
1 parent 65707a3 commit 8d4bbf9

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

drivers/platform/x86/lenovo/wmi-helpers.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include <linux/acpi.h>
20+
#include <linux/debugfs.h>
21+
#include <linux/device.h>
2022
#include <linux/cleanup.h>
2123
#include <linux/errno.h>
2224
#include <linux/export.h>
@@ -186,6 +188,38 @@ int lwmi_tm_notifier_call(enum thermal_mode *mode)
186188
}
187189
EXPORT_SYMBOL_NS_GPL(lwmi_tm_notifier_call, "LENOVO_WMI_HELPERS");
188190

191+
static struct dentry *lwmi_debugfs_dir;
192+
193+
/**
194+
* lwmi_debugfs_create_dir() - Helper function for creating a debugfs directory
195+
* for a device.
196+
* @wdev: Pointer to the WMI device to be called.
197+
*
198+
* Caller must remove the directory with debugfs_remove_recursive() on device
199+
* removal.
200+
*
201+
* Return: Pointer to the created directory.
202+
*/
203+
struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev)
204+
{
205+
return debugfs_create_dir(dev_name(&wdev->dev), lwmi_debugfs_dir);
206+
}
207+
EXPORT_SYMBOL_NS_GPL(lwmi_debugfs_create_dir, "LENOVO_WMI_HELPERS");
208+
209+
static int __init lwmi_helpers_init(void)
210+
{
211+
lwmi_debugfs_dir = debugfs_create_dir("lenovo_wmi", NULL);
212+
213+
return 0;
214+
}
215+
subsys_initcall(lwmi_helpers_init)
216+
217+
static void __exit lwmi_helpers_exit(void)
218+
{
219+
debugfs_remove_recursive(lwmi_debugfs_dir);
220+
}
221+
module_exit(lwmi_helpers_exit)
222+
189223
MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
190224
MODULE_DESCRIPTION("Lenovo WMI Helpers Driver");
191225
MODULE_LICENSE("GPL");

drivers/platform/x86/lenovo/wmi-helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct wmi_method_args_32 {
1616
u32 arg1;
1717
};
1818

19+
struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev);
20+
1921
enum lwmi_event_type {
2022
LWMI_GZ_GET_THERMAL_MODE = 0x01,
2123
};

0 commit comments

Comments
 (0)