1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #if defined(WILC_DEBUGFS)
8 #include <linux/module.h>
9 #include <linux/debugfs.h>
11 #include "wilc_wlan_if.h"
13 static struct dentry *wilc_dir;
20 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
21 static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
23 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
24 size_t count, loff_t *ppos)
29 /* only allow read from start */
33 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
34 atomic_read(&WILC_DEBUG_LEVEL));
36 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
39 static ssize_t wilc_debug_level_write(struct file *filp,
40 const char __user *buf, size_t count,
46 ret = kstrtouint_from_user(buf, count, 16, &flag);
50 if (flag > DBG_LEVEL_ALL) {
51 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
52 __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
56 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
59 pr_info("Debug-level disabled\n");
61 pr_info("Debug-level enabled\n");
66 #define FOPS(_open, _read, _write, _poll) { \
67 .owner = THIS_MODULE, \
74 struct wilc_debugfs_info_t {
78 const struct file_operations fops;
81 static struct wilc_debugfs_info_t debugfs_info[] = {
86 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
90 int wilc_debugfs_init(void)
93 struct wilc_debugfs_info_t *info;
95 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
96 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
97 info = &debugfs_info[i];
98 debugfs_create_file(info->name,
107 void wilc_debugfs_remove(void)
109 debugfs_remove_recursive(wilc_dir);